diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-01-29 15:13:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-29 15:13:25 +0800 |
commit | 6fa3fbeae84200c90ff47dde03545742a861be17 (patch) | |
tree | 215e071834d2e876aa925e651363c489324592ec /test/compress | |
parent | 4eb4cb656cc4f3850c403689cf29e529f4c67944 (diff) | |
download | tracifyjs-6fa3fbeae84200c90ff47dde03545742a861be17.tar.gz tracifyjs-6fa3fbeae84200c90ff47dde03545742a861be17.zip |
compress chained compound assignments (#2850)
Diffstat (limited to 'test/compress')
-rw-r--r-- | test/compress/collapse_vars.js | 11 | ||||
-rw-r--r-- | test/compress/reduce_vars.js | 94 |
2 files changed, 76 insertions, 29 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 970f822e..4172b33b 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -52,13 +52,8 @@ collapse_vars_side_effects_1: { console.log.bind(console)(s.charAt(i++), s.charAt(i++), s.charAt(i++), 7); } function f2() { - var log = console.log.bind(console), - s = "abcdef", - i = 2, - x = s.charAt(i++), - y = s.charAt(i++), - z = s.charAt(i++); - log(x, i, y, z, 7); + var s = "abcdef", i = 2; + console.log.bind(console)(s.charAt(i++), 5, s.charAt(i++), s.charAt(i++), 7); } function f3() { var s = "abcdef", @@ -72,7 +67,7 @@ collapse_vars_side_effects_1: { var i = 10, x = i += 2, y = i += 3; - console.log.bind(console)(x, i += 4, y, i); + console.log.bind(console)(x, i += 4, y, 19); } f1(), f2(), f3(), f4(); } diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 4009c35b..2231587d 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -76,14 +76,12 @@ modified: { console.log(a + 1); console.log(b + 1); } - function f1() { var a = 1, b = 2; --b; console.log(a + 1); console.log(b + 1); } - function f2() { var a = 1, b = 2, c = 3; b = c; @@ -92,7 +90,6 @@ modified: { console.log(a + c); console.log(a + b + c); } - function f3() { var a = 1, b = 2, c = 3; b *= c; @@ -101,7 +98,6 @@ modified: { console.log(a + c); console.log(a + b + c); } - function f4() { var a = 1, b = 2, c = 3; if (a) { @@ -114,28 +110,26 @@ modified: { console.log(a + c); console.log(a + b + c); } - function f5(a) { B = a; - console.log(A ? 'yes' : 'no'); - console.log(B ? 'yes' : 'no'); + console.log(typeof A ? "yes" : "no"); + console.log(typeof B ? "yes" : "no"); } + f0(), f1(), f2(), f3(), f4(), f5(); } expect: { function f0() { var b = 2; b++; console.log(2); - console.log(b + 1); + console.log(4); } - function f1() { var b = 2; --b; console.log(2); - console.log(b + 1); + console.log(2); } - function f2() { 3; console.log(4); @@ -143,16 +137,14 @@ modified: { console.log(4); console.log(7); } - function f3() { var b = 2; b *= 3; - console.log(1 + b); - console.log(b + 3); + console.log(7); + console.log(9); console.log(4); - console.log(1 + b + 3); + console.log(10); } - function f4() { var b = 2, c = 3; b = c; @@ -161,13 +153,33 @@ modified: { console.log(1 + c); console.log(1 + b + c); } - function f5(a) { B = a; - console.log(A ? 'yes' : 'no'); - console.log(B ? 'yes' : 'no'); + console.log(typeof A ? "yes" : "no"); + console.log(typeof B ? "yes" : "no"); } + f0(), f1(), f2(), f3(), f4(), f5(); } + expect_stdout: [ + "2", + "4", + "2", + "2", + "4", + "6", + "4", + "7", + "7", + "9", + "4", + "10", + "4", + "6", + "4", + "7", + "yes", + "yes", + ] } unsafe_evaluate: { @@ -745,7 +757,7 @@ iife: { expect: { !function(a, b, c) { b++; - console.log(0, 1 * b, 5); + console.log(0, 3, 5); }(1, 2, 3); } expect_stdout: true @@ -766,7 +778,7 @@ iife_new: { expect: { var A = new function(a, b, c) { b++; - console.log(0, 1 * b, 5); + console.log(0, 3, 5); }(1, 2, 3); } expect_stdout: true @@ -5383,3 +5395,43 @@ issue_2836: { } expect_stdout: "PASS" } + +lvalues_def_1: { + options = { + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + var b = 1; + var a = b++, b = NaN; + console.log(a, b); + } + expect: { + var b = 1; + var a = b++; + b = NaN; + console.log(a, b); + } + expect_stdout: "1 NaN" +} + +lvalues_def_2: { + options = { + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + var b = 1; + var a = b += 1, b = NaN; + console.log(a, b); + } + expect: { + var b = 1; + var a = b += 1; + b = NaN; + console.log(a, b); + } + expect_stdout: "2 NaN" +} |