From 21fc8f4630bccdb8b0a33747c2de8fd377e83138 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Tue, 15 Jun 2021 13:59:53 +0100 Subject: [PATCH] fix corner case in `switches` (#5011) fixes #5010 --- lib/compress.js | 2 +- test/compress/switches.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) 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" +}