diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-06-15 13:59:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-15 20:59:53 +0800 |
commit | 21fc8f4630bccdb8b0a33747c2de8fd377e83138 (patch) | |
tree | 9d6785d39feaae5fa3adb43c0553bb3f4f66f334 | |
parent | bf76e357723daa4fc00004a10b2b3de82a2bf33e (diff) | |
download | tracifyjs-21fc8f4630bccdb8b0a33747c2de8fd377e83138.tar.gz tracifyjs-21fc8f4630bccdb8b0a33747c2de8fd377e83138.zip |
fix corner case in `switches` (#5011)
fixes #5010
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | test/compress/switches.js | 26 |
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index 44098d74..ed3b5a39 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -8506,7 +8506,7 @@ merge(Compressor.prototype, { })); return make_node(AST_BlockStatement, self, { body: decl }).optimize(compressor); } - if (exact_match ? !branch.expression.has_side_effects(compressor) : branch === default_branch) { + if (branch === default_branch || branch === exact_match && !branch.expression.has_side_effects(compressor)) { while (branch = body[body.length - 2]) { if (branch instanceof AST_Default) break; if (!has_declarations_only(branch)) break; diff --git a/test/compress/switches.js b/test/compress/switches.js index cbaa0644..af81b54c 100644 --- a/test/compress/switches.js +++ b/test/compress/switches.js @@ -1556,3 +1556,29 @@ issue_5008_4: { } expect_stdout: "PASS" } + +issue_5010: { + options = { + dead_code: true, + evaluate: true, + switches: true, + } + input: { + var a; + switch (42) { + case console.log("PASS"): + case a: + console.log("FAIL"); + case 42: + } + } + expect: { + var a; + switch (42) { + case console.log("PASS"): + case a: + console.log("FAIL"); + } + } + expect_stdout: "PASS" +} |