Skip to content

Commit

Permalink
fix corner case in collapse_vars (#5720)
Browse files Browse the repository at this point in the history
fixes #5719
  • Loading branch information
alexlamsl authored Oct 24, 2022
1 parent fb1bff2 commit 30bf068
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
27 changes: 27 additions & 0 deletions test/compress/collapse_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 30bf068

Please sign in to comment.