Skip to content

Commit 2cb6454

Browse files
authoredJun 8, 2024··
fix corner case in merge_vars (#5830)
fixes #5829
1 parent 0991077 commit 2cb6454

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed
 

‎lib/compress.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -6719,9 +6719,11 @@ Compressor.prototype.compress = function(node) {
67196719
segments.consequent = scan_branches(level + 1, condition.left, condition.right).consequent;
67206720
break;
67216721
case "||":
6722-
case "??":
67236722
segments.alternative = scan_branches(level + 1, condition.left, null, condition.right).alternative;
67246723
break;
6724+
case "??":
6725+
segments.alternative = scan_branches(level + 1, condition.left, condition.right, condition.right).alternative;
6726+
break;
67256727
default:
67266728
condition.walk(tw);
67276729
break;

‎test/compress/nullish.js

+40
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,43 @@ issue_5266: {
344344
]
345345
node_version: ">=14"
346346
}
347+
348+
issue_5829_1: {
349+
options = {
350+
merge_vars: true,
351+
}
352+
input: {
353+
(function f(a) {
354+
var b;
355+
(!a ?? (b = 0)) || console.log(b || "PASS");
356+
})("FAIL");
357+
}
358+
expect: {
359+
(function f(a) {
360+
var b;
361+
(!a ?? (b = 0)) || console.log(b || "PASS");
362+
})("FAIL");
363+
}
364+
expect_stdout: "PASS"
365+
node_version: ">=14"
366+
}
367+
368+
issue_5829_2: {
369+
options = {
370+
merge_vars: true,
371+
}
372+
input: {
373+
(function f(a) {
374+
var b;
375+
(a ?? (b = 0)) && console.log(b || "PASS");
376+
})("FAIL");
377+
}
378+
expect: {
379+
(function f(a) {
380+
var b;
381+
(a ?? (b = 0)) && console.log(b || "PASS");
382+
})("FAIL");
383+
}
384+
expect_stdout: "PASS"
385+
node_version: ">=14"
386+
}

0 commit comments

Comments
 (0)
Please sign in to comment.