mangle shadowed lambda under `ie8` correctly (#3356)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 1 Apr 2019 07:22:00 +0000 (15:22 +0800)
committerGitHub <noreply@github.com>
Mon, 1 Apr 2019 07:22:00 +0000 (15:22 +0800)
fixes #3355

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

index 5e11441..f78b4c5 100644 (file)
@@ -198,24 +198,20 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
         }
         if (node instanceof AST_SymbolLambda) {
             var def = node.thedef;
-            if (def.orig.length == 1) {
-                redefine(node, node.scope.parent_scope);
-                node.thedef.init = def.init;
-            }
+            redefine(node, node.scope.parent_scope);
+            node.thedef.init = def.init;
             return true;
         }
     }));
 
     function redefine(node, scope) {
         var name = node.name;
-        var refs = node.thedef.references;
-        var def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
-        refs.forEach(function(ref) {
-            ref.thedef = def;
-            ref.reference(options);
+        var old_def = node.thedef;
+        var new_def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node);
+        old_def.orig.concat(old_def.references).forEach(function(node) {
+            node.thedef = new_def;
+            node.reference(options);
         });
-        node.thedef = def;
-        node.reference(options);
     }
 });
 
index dd9bae4..f98033e 100644 (file)
@@ -861,3 +861,111 @@ issue_3215_4: {
     }
     expect_stdout: "PASS"
 }
+
+issue_3355_1: {
+    mangle = {
+        ie8: false,
+    }
+    input: {
+        (function f() {
+            var f;
+        })();
+        (function g() {
+        })();
+        console.log(typeof f === typeof g);
+    }
+    expect: {
+        (function o() {
+            var o;
+        })();
+        (function o() {
+        })();
+        console.log(typeof f === typeof g);
+    }
+    expect_stdout: "true"
+}
+
+issue_3355_2: {
+    mangle = {
+        ie8: true,
+    }
+    input: {
+        (function f() {
+            var f;
+        })();
+        (function g() {
+        })();
+        console.log(typeof f === typeof g);
+    }
+    expect: {
+        (function f() {
+            var f;
+        })();
+        (function g() {
+        })();
+        console.log(typeof f === typeof g);
+    }
+    expect_stdout: "true"
+}
+
+issue_3355_3: {
+    mangle = {
+        ie8: false,
+    }
+    input: {
+        !function(a) {
+            "aaaaaaaaaa";
+            a();
+            var b = function c() {
+                var c = 42;
+                console.log("FAIL");
+            };
+        }(function() {
+            console.log("PASS");
+        });
+    }
+    expect: {
+        !function(a) {
+            "aaaaaaaaaa";
+            a();
+            var o = function a() {
+                var a = 42;
+                console.log("FAIL");
+            };
+        }(function() {
+            console.log("PASS");
+        });
+    }
+    expect_stdout: "PASS"
+}
+
+issue_3355_4: {
+    mangle = {
+        ie8: true,
+    }
+    input: {
+        !function(a) {
+            "aaaaaaaaaa";
+            a();
+            var b = function c() {
+                var c = 42;
+                console.log("FAIL");
+            };
+        }(function() {
+            console.log("PASS");
+        });
+    }
+    expect: {
+        !function(a) {
+            "aaaaaaaaaa";
+            a();
+            var o = function n() {
+                var n = 42;
+                console.log("FAIL");
+            };
+        }(function() {
+            console.log("PASS");
+        });
+    }
+    expect_stdout: "PASS"
+}