aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-05-20 11:08:22 +0100
committerGitHub <noreply@github.com>2021-05-20 18:08:22 +0800
commit4a19575e74beaf4c934581623c3372d084ebfeb7 (patch)
treebe2b0a354ed8cadb115a7a80425d4419f0ada7bd
parente0695ef5492ac227c3c381683347f939f99a1021 (diff)
downloadtracifyjs-4a19575e74beaf4c934581623c3372d084ebfeb7.tar.gz
tracifyjs-4a19575e74beaf4c934581623c3372d084ebfeb7.zip
fix corner case in `conditionals` (#4948)
fixes #4947
-rw-r--r--lib/compress.js1
-rw-r--r--test/compress/optional-chains.js30
2 files changed, 31 insertions, 0 deletions
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"
+}