diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-03-18 21:28:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-18 21:28:41 +0800 |
commit | 615ae37ca3a659df2ed304d7d30a43704fdd43ab (patch) | |
tree | ecf01cb2abf81f788743724159d99340862d0be7 /test | |
parent | 7aa7f21872a443cad6fe496b1a2f66e969b19f09 (diff) | |
download | tracifyjs-615ae37ca3a659df2ed304d7d30a43704fdd43ab.tar.gz tracifyjs-615ae37ca3a659df2ed304d7d30a43704fdd43ab.zip |
introduce `assignments` (#3345)
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/asm.js | 1 | ||||
-rw-r--r-- | test/compress/assignment.js | 53 | ||||
-rw-r--r-- | test/compress/collapse_vars.js | 2 | ||||
-rw-r--r-- | test/compress/conditionals.js | 1 | ||||
-rw-r--r-- | test/compress/evaluate.js | 35 | ||||
-rw-r--r-- | test/compress/functions.js | 5 |
6 files changed, 95 insertions, 2 deletions
diff --git a/test/compress/asm.js b/test/compress/asm.js index d7b1b62b..cebe6838 100644 --- a/test/compress/asm.js +++ b/test/compress/asm.js @@ -1,5 +1,6 @@ asm_mixed: { options = { + assignments: true, booleans: true, comparisons: true, conditionals: true, diff --git a/test/compress/assignment.js b/test/compress/assignment.js index 903380a9..ba412583 100644 --- a/test/compress/assignment.js +++ b/test/compress/assignment.js @@ -1,5 +1,6 @@ op_equals_left_local_var: { options = { + assignments: true, evaluate: true, } input: { @@ -60,6 +61,7 @@ op_equals_left_local_var: { op_equals_right_local_var: { options = { + assignments: true, evaluate: true, } input: { @@ -123,6 +125,7 @@ op_equals_right_local_var: { } op_equals_left_global_var: { options = { + assignments: true, evaluate: true, } input: { @@ -179,6 +182,7 @@ op_equals_left_global_var: { op_equals_right_global_var: { options = { + assignments: true, evaluate: true, } input: { @@ -236,3 +240,52 @@ op_equals_right_global_var: { x = g() & x; } } + +increment_decrement_1: { + options = { + assignments: true, + reduce_vars: true, + } + input: { + console.log(function(a) { + a += 1; + a -= 1; + return a; + }(42)); + } + expect: { + console.log(function(a){ + ++a; + --a; + return a; + }(42)); + } + expect_stdout: "42" +} + +increment_decrement_2: { + options = { + assignments: true, + passes: 2, + reduce_vars: true, + } + input: { + console.log(function(a) { + a = a + 1; + a = a - 1; + a += 1; + a -= 1; + return a; + }(42)); + } + expect: { + console.log(function(a){ + ++a; + --a; + ++a; + --a; + return a; + }(42)); + } + expect_stdout: "42" +} diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 6c867123..a858e000 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -944,7 +944,7 @@ collapse_vars_misc1: { function f5(x) { var z = foo(); return (5 - window.x) / z } function f6() { return window.a * window.z && zap() } function f7() { var b = window.a * window.z; return b + b } - function f8() { var b = window.a * window.z; return b + (b + 5) } + function f8() { var b = window.a * window.z; return b + (5 + b) } function f9() { var b = window.a * window.z; return bar() || b } function f10(x) { var a = 5; return a += 3; } function f11(x) { var a = 5; return a += 2; } diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js index d6d47c41..78c0ca24 100644 --- a/test/compress/conditionals.js +++ b/test/compress/conditionals.js @@ -1367,6 +1367,7 @@ cond_seq_assign_2: { cond_seq_assign_3: { options = { + assignments: true, conditionals: true, } input: { diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js index 23785284..a740cd82 100644 --- a/test/compress/evaluate.js +++ b/test/compress/evaluate.js @@ -1540,7 +1540,7 @@ issue_2926_2: { expect_stdout: "function" } -issue_2968: { +issue_2968_1: { options = { collapse_vars: true, evaluate: true, @@ -1571,6 +1571,39 @@ issue_2968: { expect_stdout: "PASS" } +issue_2968_2: { + options = { + assignments: true, + collapse_vars: true, + evaluate: true, + inline: true, + passes: 2, + reduce_vars: true, + side_effects: true, + unused: true, + } + input: { + var c = "FAIL"; + (function() { + (function(a, b) { + a <<= 0; + a && (a[(c = "PASS", 0 >>> (b += 1))] = 0); + })(42, -42); + })(); + console.log(c); + } + expect: { + var c = "FAIL"; + (function() { + a = 42, + ((a <<= 0) && (a[(c = "PASS", 0)] = 0)); + var a; + })(); + console.log(c); + } + expect_stdout: "PASS" +} + truthy_conditionals: { options = { conditionals: true, diff --git a/test/compress/functions.js b/test/compress/functions.js index 4d243a81..a52796c2 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -358,6 +358,7 @@ inner_ref: { issue_2107: { options = { + assignments: true, collapse_vars: true, inline: true, passes: 3, @@ -387,6 +388,7 @@ issue_2107: { issue_2114_1: { options = { + assignments: true, collapse_vars: true, if_return: true, inline: true, @@ -419,6 +421,7 @@ issue_2114_1: { issue_2114_2: { options = { + assignments: true, collapse_vars: true, if_return: true, inline: true, @@ -1223,6 +1226,7 @@ issue_2630_1: { issue_2630_2: { options = { + assignments: true, collapse_vars: true, inline: true, passes: 2, @@ -1320,6 +1324,7 @@ issue_2630_4: { issue_2630_5: { options = { + assignments: true, collapse_vars: true, inline: true, reduce_vars: true, |