fix corner case in switches (#5011)

fixes #5010
This commit is contained in:
Alex Lam S.L
2021-06-15 13:59:53 +01:00
committed by GitHub
parent bf76e35772
commit 21fc8f4630
2 changed files with 27 additions and 1 deletions

View File

@@ -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;

View File

@@ -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"
}