From ce27bcd69a0a66bf145ee2f14927a3cfec9b0202 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 8 Jan 2018 14:30:18 +0800 Subject: compress loops with immediate `break` (#2746) fixes #2740 --- test/compress/loops.js | 113 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) (limited to 'test') 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" +} -- cgit v1.2.3