Skip to content

Commit 30bf068

Browse files
authored
fix corner case in collapse_vars (#5720)
fixes #5719
1 parent fb1bff2 commit 30bf068

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/compress.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2498,7 +2498,7 @@ Compressor.prototype.compress = function(node) {
24982498
hit_index++;
24992499
}
25002500
branch.expression = branch.expression.transform(tt);
2501-
if (!replace_all) break;
2501+
if (!replace_all || verify_ref) break;
25022502
scan_rhs = false;
25032503
}
25042504
}

test/compress/collapse_vars.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10121,3 +10121,30 @@ issue_5643: {
1012110121
}
1012210122
expect_stdout: "42"
1012310123
}
10124+
10125+
issue_5719: {
10126+
options = {
10127+
collapse_vars: true,
10128+
reduce_vars: true,
10129+
toplevel: true,
10130+
}
10131+
input: {
10132+
var a = 42, b;
10133+
switch (b = a) {
10134+
case a:
10135+
case b:
10136+
case a++:
10137+
}
10138+
console.log(a === b++ ? "PASS" : "FAIL");
10139+
}
10140+
expect: {
10141+
var a = 42, b;
10142+
switch (b = a) {
10143+
case a:
10144+
case b:
10145+
case a++:
10146+
}
10147+
console.log(a === b++ ? "PASS" : "FAIL");
10148+
}
10149+
expect_stdout: "PASS"
10150+
}

0 commit comments

Comments
 (0)