suppress switch branch de-duplication upon side effects (#1682)
fixes #1679
This commit is contained in:
@@ -2551,12 +2551,14 @@ merge(Compressor.prototype, {
|
|||||||
} else {
|
} else {
|
||||||
body.push(branch);
|
body.push(branch);
|
||||||
}
|
}
|
||||||
blocks[key] = branch;
|
|
||||||
fallthrough = false;
|
fallthrough = false;
|
||||||
} else {
|
} else {
|
||||||
body.push(branch);
|
body.push(branch);
|
||||||
fallthrough = true;
|
fallthrough = true;
|
||||||
}
|
}
|
||||||
|
if (branch instanceof AST_Case && branch.expression.has_side_effects(compressor))
|
||||||
|
blocks = Object.create(null);
|
||||||
|
if (!fallthrough) blocks[key] = branch;
|
||||||
}
|
}
|
||||||
for (; i < len && fallthrough; i++) {
|
for (; i < len && fallthrough; i++) {
|
||||||
branch = self.body[i];
|
branch = self.body[i];
|
||||||
|
|||||||
@@ -434,3 +434,50 @@ issue_1674: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_1679: {
|
||||||
|
options = {
|
||||||
|
dead_code: true,
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
function f() {
|
||||||
|
switch (--b) {
|
||||||
|
default:
|
||||||
|
case !function x() {}:
|
||||||
|
break;
|
||||||
|
case b--:
|
||||||
|
switch (0) {
|
||||||
|
default:
|
||||||
|
case a--:
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case (a++):
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 100, b = 10;
|
||||||
|
function f() {
|
||||||
|
switch (--b) {
|
||||||
|
default:
|
||||||
|
case !function x() {}:
|
||||||
|
break;
|
||||||
|
case b--:
|
||||||
|
switch (0) {
|
||||||
|
default:
|
||||||
|
case a--:
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case (a++):
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(a, b);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user