From 9a137e8613e49066a54f2a1b734a559c05338f11 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 14 Dec 2017 02:59:59 +0800 Subject: drop local assign-only variable in `return` (#2587) --- test/compress/collapse_vars.js | 10 ++--- test/compress/dead-code.js | 90 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 1323116a..bd1362b1 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -591,7 +591,7 @@ collapse_vars_switch: { collapse_vars_assignment: { options = { - collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true, + collapse_vars:true, sequences:true, properties:true, conditionals:true, comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true, keep_fargs:true, if_return:true, join_vars:true, side_effects:true } @@ -639,7 +639,7 @@ collapse_vars_assignment: { return a = a; } function f1(c) { - return 1 - 3 / c + return 1 - 3 / c; } function f2(c) { return log(c = 3 / c - 7); @@ -664,7 +664,7 @@ collapse_vars_assignment: { collapse_vars_lvalues: { options = { - collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true, + collapse_vars:true, sequences:true, properties:true, conditionals:true, comparisons:true, evaluate:true, booleans:true, loops:true, unused:"keep_assign", hoist_funs:true, keep_fargs:true, if_return:true, join_vars:true, side_effects:true @@ -697,7 +697,7 @@ collapse_vars_lvalues: { collapse_vars_lvalues_drop_assign: { options = { - collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true, + collapse_vars:true, sequences:true, properties:true, conditionals:true, comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true, keep_fargs:true, if_return:true, join_vars:true, side_effects:true, passes:3 } @@ -729,7 +729,7 @@ collapse_vars_lvalues_drop_assign: { collapse_vars_misc1: { options = { - collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true, + collapse_vars:true, sequences:true, properties:true, conditionals:true, comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true, keep_fargs:true, if_return:true, join_vars:true, side_effects:true, reduce_funcs: true, reduce_vars:true diff --git a/test/compress/dead-code.js b/test/compress/dead-code.js index 9baf9984..ca7ad5c0 100644 --- a/test/compress/dead-code.js +++ b/test/compress/dead-code.js @@ -417,3 +417,93 @@ global_fns: { "RangeError", ] } + +collapse_vars_assignment: { + options = { + collapse_vars: true, + dead_code: true, + passes: 2, + unused: true, + } + input: { + function f0(c) { + var a = 3 / c; + return a = a; + } + } + expect: { + function f0(c) { + return 3 / c; + } + } +} + +collapse_vars_lvalues_drop_assign: { + options = { + collapse_vars: true, + dead_code: true, + unused: true, + } + input: { + function f0(x) { var i = ++x; return x += i; } + function f1(x) { var a = (x -= 3); return x += a; } + function f2(x) { var z = x, a = ++z; return z += a; } + } + expect: { + function f0(x) { var i = ++x; return x + i; } + function f1(x) { var a = (x -= 3); return x + a; } + function f2(x) { var z = x, a = ++z; return z + a; } + } +} + +collapse_vars_misc1: { + options = { + collapse_vars: true, + dead_code: true, + unused: true, + } + input: { + function f10(x) { var a = 5, b = 3; return a += b; } + function f11(x) { var a = 5, b = 3; return a += --b; } + } + expect: { + function f10(x) { return 5 + 3; } + function f11(x) { var b = 3; return 5 + --b; } + } +} + +return_assignment: { + options = { + dead_code: true, + unused: true, + } + input: { + function f1(a, b, c) { + return a = x(), b = y(), b = a && (c >>= 5); + } + function f2() { + return e = x(); + } + function f3(e) { + return e = x(); + } + function f4() { + var e; + return e = x(); + } + } + expect: { + function f1(a, b, c) { + return a = x(), y(), a && (c >> 5); + } + function f2() { + return e = x(); + } + function f3(e) { + return x(); + } + function f4() { + return x(); + } + } +} -- cgit v1.2.3