fix corner case in `dead_code` (#3969)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 8 Jun 2020 05:42:09 +0000 (06:42 +0100)
committerGitHub <noreply@github.com>
Mon, 8 Jun 2020 05:42:09 +0000 (13:42 +0800)
fixes #3967

lib/compress.js
test/compress/dead-code.js

index c8c08a0..a56e933 100644 (file)
@@ -3938,7 +3938,8 @@ merge(Compressor.prototype, {
         });
         def(AST_Binary, function(compressor) {
             return this.left.may_throw(compressor)
-                || this.right.may_throw(compressor);
+                || this.right.may_throw(compressor)
+                || this.operator == "in" && !is_object(this.right.tail_node());
         });
         def(AST_Block, function(compressor) {
             return any(this.body, compressor);
index 22eb0d9..5506b95 100644 (file)
@@ -1193,3 +1193,24 @@ self_assignments: {
     }
     expect_stdout: "PASS 2 PASS PASS"
 }
+
+issue_3967: {
+    options = {
+        dead_code: true,
+    }
+    input: {
+        var a = "FAIL";
+        try {
+            a = 0 in (a = "PASS");
+        } catch (e) {}
+        console.log(a);
+    }
+    expect: {
+        var a = "FAIL";
+        try {
+            a = 0 in (a = "PASS");
+        } catch (e) {}
+        console.log(a);
+    }
+    expect_stdout: "PASS"
+}