fix corner case in `dead_code` & `ie8` (#3494)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 17 Oct 2019 01:58:05 +0000 (09:58 +0800)
committerGitHub <noreply@github.com>
Thu, 17 Oct 2019 01:58:05 +0000 (09:58 +0800)
fixes #3493

lib/compress.js
test/compress/ie8.js

index e39435c..4b0ceee 100644 (file)
@@ -888,8 +888,10 @@ merge(Compressor.prototype, {
     });
 
     AST_SymbolRef.DEFMETHOD("is_immutable", function() {
-        var orig = this.definition().orig;
-        return orig.length == 1 && orig[0] instanceof AST_SymbolLambda;
+        var def = this.definition();
+        if (def.orig.length != 1) return false;
+        var sym = def.orig[0];
+        return sym instanceof AST_SymbolLambda && def.scope.name === sym;
     });
 
     function is_lhs_read_only(lhs, compressor) {
index 223da32..4637451 100644 (file)
@@ -1887,3 +1887,75 @@ issue_3486_ie8: {
     }
     expect_stdout: "PASS"
 }
+
+issue_3493: {
+    options = {
+        dead_code: true,
+        ie8: false,
+    }
+    input: {
+        var c = "PASS";
+        (function() {
+            try {
+                (function a() {
+                    throw {};
+                })();
+            } catch (a) {
+                a >>= 0;
+                a && (c = "FAIL");
+            }
+        })();
+        console.log(c);
+    }
+    expect: {
+        var c = "PASS";
+        (function() {
+            try {
+                (function a() {
+                    throw {};
+                })();
+            } catch (a) {
+                a >>= 0;
+                a && (c = "FAIL");
+            }
+        })();
+        console.log(c);
+    }
+    expect_stdout: "PASS"
+}
+
+issue_3493_ie8: {
+    options = {
+        dead_code: true,
+        ie8: true,
+    }
+    input: {
+        var c = "PASS";
+        (function() {
+            try {
+                (function a() {
+                    throw {};
+                })();
+            } catch (a) {
+                a >>= 0;
+                a && (c = "FAIL");
+            }
+        })();
+        console.log(c);
+    }
+    expect: {
+        var c = "PASS";
+        (function() {
+            try {
+                (function a() {
+                    throw {};
+                })();
+            } catch (a) {
+                a >>= 0;
+                a && (c = "FAIL");
+            }
+        })();
+        console.log(c);
+    }
+    expect_stdout: "PASS"
+}