fix corner case in `reduce_vars` (#3975)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 9 Jun 2020 02:33:47 +0000 (03:33 +0100)
committerGitHub <noreply@github.com>
Tue, 9 Jun 2020 02:33:47 +0000 (10:33 +0800)
fixes #3974

lib/compress.js
test/compress/reduce_vars.js

index d82c812..907c9e7 100644 (file)
@@ -4032,7 +4032,9 @@ merge(Compressor.prototype, {
             return all(this.elements);
         });
         def(AST_Binary, function() {
-            return this.left.is_constant_expression() && this.right.is_constant_expression();
+            return this.left.is_constant_expression()
+                && this.right.is_constant_expression()
+                && (this.operator != "in" || is_object(this.right.tail_node()));
         });
         def(AST_Constant, return_true);
         def(AST_Lambda, function(scope) {
index 41eb009..9010fb1 100644 (file)
@@ -7358,3 +7358,28 @@ issue_3958: {
         "0",
     ]
 }
+
+issue_3974: {
+    options = {
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        try {
+            var a = 0 in 0;
+            0 && a;
+        } catch (e) {
+            console.log("PASS");
+        }
+    }
+    expect: {
+        try {
+            var a = 0 in 0;
+            0 && a;
+        } catch (e) {
+            console.log("PASS");
+        }
+    }
+    expect_stdout: "PASS"
+}