fix corner case in `ie8` (#4016)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 20 Jul 2020 18:32:20 +0000 (19:32 +0100)
committerGitHub <noreply@github.com>
Mon, 20 Jul 2020 18:32:20 +0000 (02:32 +0800)
fixes #4015

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

index 6631476..3297b8e 100644 (file)
@@ -230,6 +230,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
         } else {
             new_def = scope.def_variable(node);
         }
+        old_def.defun = new_def.scope;
         old_def.orig.concat(old_def.references).forEach(function(node) {
             node.thedef = new_def;
             node.reference(options);
index df06c62..2115dbc 100644 (file)
@@ -2544,12 +2544,12 @@ issue_3999: {
     expect: {
         (function() {
             (function f() {
-                for (var c = 0; c < 2; c++)
+                for (var o = 0; o < 2; o++)
                     try {
                         f[0];
                     } catch (f) {
                         var f = 0;
-                        console.log(c);
+                        console.log(o);
                     }
             })();
         })(typeof f);
@@ -2593,3 +2593,44 @@ issue_4001: {
     }
     expect_stdout: "undefined"
 }
+
+issue_4015: {
+    rename = true
+    mangle = {
+        ie8: true,
+        toplevel: true,
+    }
+    input: {
+        var n, a = 0, b;
+        function f() {
+            try {
+                throw 0;
+            } catch (b) {
+                (function g() {
+                    (function b() {
+                        a++;
+                    })();
+                })();
+            }
+        }
+        f();
+        console.log(a);
+    }
+    expect: {
+        var n, o = 0, c;
+        function t() {
+            try {
+                throw 0;
+            } catch (c) {
+                (function n() {
+                    (function c() {
+                        o++;
+                    })();
+                })();
+            }
+        }
+        t();
+        console.log(o);
+    }
+    expect_stdout: "1"
+}