diff --git a/lib/compress.js b/lib/compress.js index 7b8e17b8..8975f47b 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -11412,6 +11412,7 @@ merge(Compressor.prototype, { function is_tail_equivalent(consequent, alternative) { if (consequent.TYPE != alternative.TYPE) return; + if (consequent.optional != alternative.optional) return; if (consequent instanceof AST_Call) { if (arg_diff(consequent, alternative) != -1) return; return consequent.TYPE != "Call" diff --git a/test/compress/optional-chains.js b/test/compress/optional-chains.js index 7f61263c..ced841d2 100644 --- a/test/compress/optional-chains.js +++ b/test/compress/optional-chains.js @@ -275,3 +275,33 @@ issue_4928: { expect_stdout: "undefined" node_version: ">=14" } + +issue_4947_1: { + options = { + conditionals: true, + } + input: { + console.log(console.foo ? 42..p : console.bar?.p); + } + expect: { + console.log(console.foo ? 42..p : console.bar?.p); + } + expect_stdout: "undefined" + node_version: ">=14" +} + +issue_4947_2: { + options = { + conditionals: true, + } + input: { + var log = console.log, fail; + log("PASS") ? log(42) : fail?.(42); + } + expect: { + var log = console.log, fail; + log("PASS") ? log(42) : fail?.(42); + } + expect_stdout: "PASS" + node_version: ">=14" +}