fix corner case in merge_vars (#5830)

fixes #5829
This commit is contained in:
Alex Lam S.L
2024-06-08 20:15:37 +03:00
committed by GitHub
parent 09910771a1
commit 2cb6454b1f
2 changed files with 43 additions and 1 deletions

View File

@@ -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;

View File

@@ -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"
}