diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-04-18 13:38:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-18 13:38:42 +0800 |
commit | 5d9f1da3abc58bce95dd240bd586bedb4eb04771 (patch) | |
tree | d9a2ef3198cf398c04a44d52cd74285cfb97fc1b /test/compress/reduce_vars.js | |
parent | d1aa09c5c7af14bf5f17cc7ea2ab5d6be20e3220 (diff) | |
download | tracifyjs-5d9f1da3abc58bce95dd240bd586bedb4eb04771.tar.gz tracifyjs-5d9f1da3abc58bce95dd240bd586bedb4eb04771.zip |
support safe reassignments in `reduce_vars` (#1823)
`var a=1;a=2;x(a)` => `x(2)`
fix pre-existing issues
- reference counting on assignment
- walking of anonymous functions
- chained assignment
Diffstat (limited to 'test/compress/reduce_vars.js')
-rw-r--r-- | test/compress/reduce_vars.js | 102 |
1 files changed, 86 insertions, 16 deletions
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index ad2c90bc..c5f26904 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -66,7 +66,7 @@ modified: { conditionals : true, evaluate : true, reduce_vars : true, - unused : true + unused : true, } input: { function f0() { @@ -136,12 +136,11 @@ modified: { } function f2() { - var b = 2; - b = 3; - console.log(1 + b); - console.log(b + 3); + 3; console.log(4); - console.log(1 + b + 3); + console.log(6); + console.log(4); + console.log(7); } function f3() { @@ -375,12 +374,11 @@ passes: { } expect: { function f() { - var b = 2; - b = 3; - console.log(1 + b); - console.log(b + 3); + 3; console.log(4); - console.log(1 + b + 3); + console.log(6); + console.log(4); + console.log(7); } } } @@ -573,7 +571,7 @@ inner_var_label: { } } -inner_var_for: { +inner_var_for_1: { options = { evaluate: true, reduce_vars: true, @@ -602,6 +600,29 @@ inner_var_for: { } } +inner_var_for_2: { + options = { + evaluate: true, + reduce_vars: true, + unused: true, + } + input: { + !function() { + var a = 1; + for (var b = 1; --b;) var a = 2; + console.log(a); + }(); + } + expect: { + !function() { + a = 1; + for (var b = 1; --b;) var a = 2; + console.log(a); + }(); + } + expect_stdout: "1" +} + inner_var_for_in_1: { options = { evaluate: true, @@ -1828,10 +1849,7 @@ redefine_farg_3: { console.log(function(a) { var a; return typeof a; - }([]), "number", function(a) { - var a = void 0; - return typeof a; - }([])); + }([]), "number", "undefined"); } expect_stdout: "object number undefined" } @@ -2115,6 +2133,27 @@ var_assign_5: { expect_stdout: "2 undefined" } +var_assign_6: { + options = { + evaluate: true, + reduce_vars: true, + unused: true, + } + input: { + !function() { + var a = function(){}(a = 1); + console.log(a); + }(); + } + expect: { + !function() { + var a = function(){}(a = 1); + console.log(a); + }(); + } + expect_stdout: "undefined" +} + immutable: { options = { evaluate: true, @@ -2263,3 +2302,34 @@ cond_assign: { } expect_stdout: "undefined" } + +iife_assign: { + options = { + evaluate: true, + reduce_vars: true, + unused: true, + } + input: { + !function() { + var a = 1, b = 0; + !function() { + b++; + return; + a = 2; + }(); + console.log(a); + }(); + } + expect: { + !function() { + var a = 1, b = 0; + !function() { + b++; + return; + a = 2; + }(); + console.log(a); + }(); + } + expect_stdout: "1" +} |