Skip to content

Commit

Permalink
fix corner case in merge_vars (#5830)
Browse files Browse the repository at this point in the history
fixes #5829
  • Loading branch information
alexlamsl authored Jun 8, 2024
1 parent 0991077 commit 2cb6454
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -6719,9 +6719,11 @@ Compressor.prototype.compress = function(node) {
segments.consequent = scan_branches(level + 1, condition.left, condition.right).consequent;
break;
case "||":
case "??":
segments.alternative = scan_branches(level + 1, condition.left, null, condition.right).alternative;
break;
case "??":
segments.alternative = scan_branches(level + 1, condition.left, condition.right, condition.right).alternative;
break;
default:
condition.walk(tw);
break;
Expand Down
40 changes: 40 additions & 0 deletions test/compress/nullish.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,43 @@ issue_5266: {
]
node_version: ">=14"
}

issue_5829_1: {
options = {
merge_vars: true,
}
input: {
(function f(a) {
var b;
(!a ?? (b = 0)) || console.log(b || "PASS");
})("FAIL");
}
expect: {
(function f(a) {
var b;
(!a ?? (b = 0)) || console.log(b || "PASS");
})("FAIL");
}
expect_stdout: "PASS"
node_version: ">=14"
}

issue_5829_2: {
options = {
merge_vars: true,
}
input: {
(function f(a) {
var b;
(a ?? (b = 0)) && console.log(b || "PASS");
})("FAIL");
}
expect: {
(function f(a) {
var b;
(a ?? (b = 0)) && console.log(b || "PASS");
})("FAIL");
}
expect_stdout: "PASS"
node_version: ">=14"
}

0 comments on commit 2cb6454

Please sign in to comment.