diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-01-08 14:30:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-08 14:30:18 +0800 |
commit | ce27bcd69a0a66bf145ee2f14927a3cfec9b0202 (patch) | |
tree | 774dc5746df1e5cc9a54dd7ac52b87346bd3fef1 /test/compress/loops.js | |
parent | 9336cc824739f6e594e7c020a49b2d17b1faaec2 (diff) | |
download | tracifyjs-ce27bcd69a0a66bf145ee2f14927a3cfec9b0202.tar.gz tracifyjs-ce27bcd69a0a66bf145ee2f14927a3cfec9b0202.zip |
compress loops with immediate `break` (#2746)
fixes #2740
Diffstat (limited to 'test/compress/loops.js')
-rw-r--r-- | test/compress/loops.js | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/test/compress/loops.js b/test/compress/loops.js index 3538c221..a6ebd359 100644 --- a/test/compress/loops.js +++ b/test/compress/loops.js @@ -492,3 +492,116 @@ dead_code_condition: { } expect_stdout: "1" } + +issue_2740_1: { + options = { + dead_code: true, + loops: true, + } + input: { + for (; ; ) break; + for (a(); ; ) break; + for (; b(); ) break; + for (c(); d(); ) break; + for (; ; e()) break; + for (f(); ; g()) break; + for (; h(); i()) break; + for (j(); k(); l()) break; + } + expect: { + a(); + b(); + c(); + d(); + f(); + h(); + j(); + k(); + } +} + +issue_2740_2: { + options = { + dead_code: true, + loops: true, + passes: 2, + } + input: { + L1: while (x()) { + break L1; + } + } + expect: { + x(); + } +} + +issue_2740_3: { + options = { + dead_code: true, + loops: true, + } + input: { + L1: for (var x = 0; x < 3; x++) { + L2: for (var y = 0; y < 2; y++) { + break L1; + } + } + console.log(x, y); + } + expect: { + L1: for (var x = 0; x < 3; x++) + for (var y = 0; y < 2; y++) + break L1; + console.log(x, y); + } + expect_stdout: "0 0" +} + +issue_2740_4: { + options = { + dead_code: true, + loops: true, + passes: 2, + } + input: { + L1: for (var x = 0; x < 3; x++) { + L2: for (var y = 0; y < 2; y++) { + break L2; + } + } + console.log(x, y); + } + expect: { + for (var x = 0; x < 3; x++) { + var y = 0; + y < 2; + } + console.log(x, y); + } + expect_stdout: "3 0" +} + +issue_2740_5: { + options = { + dead_code: true, + loops: true, + passes: 2, + } + input: { + L1: for (var x = 0; x < 3; x++) { + break L1; + L2: for (var y = 0; y < 2; y++) { + break L2; + } + } + console.log(x, y); + } + expect: { + var x = 0; + x < 3; + var y; + console.log(x,y); + } + expect_stdout: "0 undefined" +} |