diff --git a/lib/output.js b/lib/output.js index 3e140cac4..03e952f84 100644 --- a/lib/output.js +++ b/lib/output.js @@ -971,6 +971,10 @@ function OutputStream(options) { return true; } + if (po === "??" && (so === "||" || so === "&&")) { + return true; + } + const pp = PRECEDENCE[po]; const sp = PRECEDENCE[so]; if (pp > sp diff --git a/test/compress/nullish.js b/test/compress/nullish.js index 4d108616c..52bf27af0 100644 --- a/test/compress/nullish.js +++ b/test/compress/nullish.js @@ -127,3 +127,21 @@ nullish_coalescing_mandatory_parens: { expect_exact: "(x??y)||z;x||(y??z);" } + +nullish_coalescing_parens: { + input: { + console.log((false || null) ?? "PASS"); + console.log(null ?? (true && "PASS")); + console.log((null ?? 0) || "PASS"); + console.log(null || (null ?? "PASS")); + } + + node_version: ">=14" + + expect_stdout: [ + "PASS", + "PASS", + "PASS", + "PASS", + ] +}