diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-09-19 18:45:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-20 01:45:52 +0800 |
commit | 3c609e2f4a925b3c47bfa2b9185a353295f353b3 (patch) | |
tree | d696a42ca1da86111822ca0d79a797326fbc8090 | |
parent | f0ae03ed3933fb967921924dc524f4cca8587ce4 (diff) | |
download | tracifyjs-3c609e2f4a925b3c47bfa2b9185a353295f353b3.tar.gz tracifyjs-3c609e2f4a925b3c47bfa2b9185a353295f353b3.zip |
enhance `unused` (#4129)
-rw-r--r-- | lib/compress.js | 7 | ||||
-rw-r--r-- | test/compress/collapse_vars.js | 7 | ||||
-rw-r--r-- | test/compress/drop-unused.js | 10 | ||||
-rw-r--r-- | test/compress/keep_fargs.js | 1 | ||||
-rw-r--r-- | test/compress/reduce_vars.js | 4 |
5 files changed, 17 insertions, 12 deletions
diff --git a/lib/compress.js b/lib/compress.js index 0f9fa6b2..3059c932 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4747,6 +4747,13 @@ merge(Compressor.prototype, { })); } } + } else if (node instanceof AST_UnaryPostfix + && node.expression instanceof AST_SymbolRef + && indexOf_assign(node.expression.definition(), node) < 0) { + return make_node(AST_UnaryPrefix, node, { + operator: "+", + expression: node.expression + }); } } if (node instanceof AST_Call) calls_to_drop_args.push(node); diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 709fc6b7..24fadceb 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -62,18 +62,18 @@ collapse_vars_side_effects_1: { expect: { function f1() { var s = "abcdef", i = 2; - console.log.bind(console)(s.charAt(i++), s.charAt(i++), s.charAt(4), 7); + console.log.bind(console)(s.charAt(i++), s.charAt(+i), s.charAt(4), 7); } function f2() { var s = "abcdef", i = 2; - console.log.bind(console)(s.charAt(i++), 5, s.charAt(i++), s.charAt(i++), 7); + console.log.bind(console)(s.charAt(i++), 5, s.charAt(i++), s.charAt(+i), 7); } function f3() { var s = "abcdef", i = 2, log = console.log.bind(console), x = s.charAt(i++), - y = s.charAt(i++); + y = s.charAt(+i); log(x, s.charAt(4), y, 7); } function f4() { @@ -3073,7 +3073,6 @@ issue_2298: { expect: { !function() { (function() { - 0; try { !function(b) { (void 0)[1] = "foo"; diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index 3e2b54f2..46f273e9 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -1730,7 +1730,7 @@ chained_3: { expect: { console.log(function(a, b) { var c = b; - b++; + +b; return c; }(0, 2)); } @@ -2737,7 +2737,7 @@ issue_3962_1: { 0..toString(); } while (0); if (c) console.log("PASS"); - }((a--, 1)), 0); + }(1), 0); void 0; } expect_stdout: "PASS" @@ -2770,7 +2770,7 @@ issue_3962_2: { 0..toString(); } while (0); if (c) console.log("PASS"); - }((a--, 1)), 0); + }(1), 0); } expect_stdout: "PASS" } @@ -2853,11 +2853,11 @@ issue_4025: { console.log(a, b, d); } expect: { - var d, c = 0; + var c = 0; try { console.log(c); } finally { - d = c + 1; + var d = c + 1; c = 0; } console.log(1, 1, d); diff --git a/test/compress/keep_fargs.js b/test/compress/keep_fargs.js index e42b3978..e1737081 100644 --- a/test/compress/keep_fargs.js +++ b/test/compress/keep_fargs.js @@ -306,7 +306,6 @@ issue_2298: { expect: { !function() { (function() { - 0; try { !function() { (void 0)[1] = "foo"; diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index c911efe0..153ac5d4 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -120,7 +120,7 @@ modified: { expect: { function f0() { var b = 2; - b++; + +b; console.log(2); console.log(4); } @@ -5590,7 +5590,7 @@ lvalues_def_1: { } expect: { var b = 1; - var a = b++, b = NaN; + var a = +b, b = NaN; console.log(a, b); } expect_stdout: "1 NaN" |