fix corner case in `mangle` (#4528)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 9 Jan 2021 20:20:43 +0000 (20:20 +0000)
committerGitHub <noreply@github.com>
Sat, 9 Jan 2021 20:20:43 +0000 (04:20 +0800)
fixes #4527

lib/scope.js
test/compress/const.js

index ea66281..f4a18ca 100644 (file)
@@ -611,6 +611,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
             if (!(sym instanceof AST_SymbolConst)) return false;
             var scope = def.scope.resolve();
             if (def.scope === scope) return false;
+            if (def.scope.parent_scope.find_variable(sym.name)) return false;
             redef = scope.def_variable(sym);
             scope.to_mangle.push(redef);
         }
index 0281fd8..38cd8fb 100644 (file)
@@ -1399,3 +1399,38 @@ issue_4365_2: {
     }
     expect_stdout: true
 }
+
+issue_4527: {
+    mangle = {}
+    input: {
+        (function() {
+            try {
+                throw 1;
+            } catch (a) {
+                try {
+                    const a = FAIL;
+                } finally {
+                    if (!b)
+                        return console.log("aaaa");
+                }
+            }
+            var b;
+        })();
+    }
+    expect: {
+        (function() {
+            try {
+                throw 1;
+            } catch (a) {
+                try {
+                    const a = FAIL;
+                } finally {
+                    if (!t)
+                        return console.log("aaaa");
+                }
+            }
+            var t;
+        })();
+    }
+    expect_stdout: "aaaa"
+}