mangle unused nested `AST_SymbolCatch` correctly (#3038)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 30 Mar 2018 07:23:09 +0000 (16:23 +0900)
committerGitHub <noreply@github.com>
Fri, 30 Mar 2018 07:23:09 +0000 (16:23 +0900)
fixes #3035

lib/scope.js
test/compress/ie8.js [moved from test/compress/screw-ie8.js with 85% similarity]

index 7cbd82c..a943152 100644 (file)
@@ -434,16 +434,19 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){
             var redef = def.redefined();
             if (redef) {
                 redefined.push(def);
-                def.references.forEach(function(ref) {
-                    ref.thedef = redef;
-                    ref.reference(options);
-                    ref.thedef = def;
-                });
+                reference(node.argname);
+                def.references.forEach(reference);
             }
             descend();
             if (!redef) mangle(def);
             return true;
         }
+
+        function reference(sym) {
+            sym.thedef = redef;
+            sym.reference(options);
+            sym.thedef = def;
+        }
     });
     this.walk(tw);
     redefined.forEach(mangle);
similarity index 85%
rename from test/compress/screw-ie8.js
rename to test/compress/ie8.js
index 3a95eb6..b21b841 100644 (file)
@@ -464,3 +464,77 @@ issue_2976_2: {
     }
     expect_stdout: "PASS"
 }
+
+issue_3035: {
+    mangle = {
+        ie8: false,
+    }
+    input: {
+        var c = "FAIL";
+        (function(a) {
+            try {
+                throw 1;
+            } catch (b) {
+                try {
+                    throw 0;
+                } catch (a) {
+                    b && (c = "PASS");
+                }
+            }
+        })();
+        console.log(c);
+    }
+    expect: {
+        var c = "FAIL";
+        (function(o) {
+            try {
+                throw 1;
+            } catch (t) {
+                try {
+                    throw 0;
+                } catch (o) {
+                    t && (c = "PASS");
+                }
+            }
+        })();
+        console.log(c);
+    }
+    expect_stdout: "PASS"
+}
+
+issue_3035_ie8: {
+    mangle = {
+        ie8: true,
+    }
+    input: {
+        var c = "FAIL";
+        (function(a) {
+            try {
+                throw 1;
+            } catch (b) {
+                try {
+                    throw 0;
+                } catch (a) {
+                    b && (c = "PASS");
+                }
+            }
+        })();
+        console.log(c);
+    }
+    expect: {
+        var c = "FAIL";
+        (function(t) {
+            try {
+                throw 1;
+            } catch (o) {
+                try {
+                    throw 0;
+                } catch (t) {
+                    o && (c = "PASS");
+                }
+            }
+        })();
+        console.log(c);
+    }
+    expect_stdout: "PASS"
+}