fix corner case in collapse_vars

fixes #5719
This commit is contained in:
alexlamsl 2022-10-24 20:40:39 +08:00
parent fb1bff2c0a
commit 8ed2ee7496
2 changed files with 28 additions and 1 deletions

View File

@ -2498,7 +2498,7 @@ Compressor.prototype.compress = function(node) {
hit_index++;
}
branch.expression = branch.expression.transform(tt);
if (!replace_all) break;
if (!replace_all || verify_ref) break;
scan_rhs = false;
}
}

View File

@ -10121,3 +10121,30 @@ issue_5643: {
}
expect_stdout: "42"
}
issue_5719: {
options = {
collapse_vars: true,
reduce_vars: true,
toplevel: true,
}
input: {
var a = 42, b;
switch (b = a) {
case a:
case b:
case a++:
}
console.log(a === b++ ? "PASS" : "FAIL");
}
expect: {
var a = 42, b;
switch (b = a) {
case a:
case b:
case a++:
}
console.log(a === b++ ? "PASS" : "FAIL");
}
expect_stdout: "PASS"
}