fix corner case in `comparisons` (#4680)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 24 Feb 2021 13:38:44 +0000 (13:38 +0000)
committerGitHub <noreply@github.com>
Wed, 24 Feb 2021 13:38:44 +0000 (13:38 +0000)
fixes #4679

lib/compress.js
test/compress/nullish.js

index 7f9a8dd..93023e1 100644 (file)
@@ -3618,6 +3618,8 @@ merge(Compressor.prototype, {
                 return this.left.is_defined(compressor) && this.right.is_defined(compressor);
               case "||":
                 return this.left.is_truthy() || this.right.is_defined(compressor);
+              case "??":
+                return this.left.is_defined(compressor) || this.right.is_defined(compressor);
               default:
                 return true;
             }
index e8f5ad6..a8526ca 100644 (file)
@@ -109,3 +109,22 @@ conditional_assignment_4: {
     expect_stdout: "PASS"
     node_version: ">=14"
 }
+
+issue_4679: {
+    options = {
+        comparisons: true,
+        ie8: true,
+    }
+    input: {
+        var a;
+        if (void 0 === (undefined ?? a))
+            console.log("PASS");
+    }
+    expect: {
+        var a;
+        if (void 0 === (undefined ?? a))
+            console.log("PASS");
+    }
+    expect_stdout: "PASS"
+    node_version: ">=14"
+}