fix corner case in `ie8` & `reduce_vars` (#3706)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 5 Feb 2020 20:03:22 +0000 (20:03 +0000)
committerGitHub <noreply@github.com>
Wed, 5 Feb 2020 20:03:22 +0000 (20:03 +0000)
fixes #3703

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

index 32d0b67..b190ef9 100644 (file)
@@ -6964,9 +6964,9 @@ merge(Compressor.prototype, {
                             var fn = node.fixed_value();
                             if (!(fn instanceof AST_Lambda)) return;
                             if (!fn.name) return;
-                            var fn_def = fn.name.definition();
-                            if (fn_def.scope !== fn.name.scope) return;
-                            if (fixed.variables.get(fn.name.name) !== fn_def) return;
+                            if (fn.name.definition() !== def) return;
+                            if (def.scope !== fn.name.scope) return;
+                            if (fixed.variables.get(fn.name.name) !== def) return;
                             fn.name = fn.name.clone();
                             var value_def = value.variables.get(fn.name.name) || value.def_function(fn.name);
                             node.thedef = value_def;
index f8ce35d..7ec8037 100644 (file)
@@ -2361,3 +2361,40 @@ issue_3542: {
     }
     expect_stdout: "1"
 }
+
+issue_3703: {
+    options = {
+        ie8: true,
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        var a = "PASS";
+        function f() {
+            var b;
+            function g() {
+                a = "FAIL";
+            }
+            var c = g;
+            function h() {
+                f;
+            }
+            a ? b |= c : b.p;
+        }
+        f();
+        console.log(a);
+    }
+    expect: {
+        var a = "PASS";
+        (function() {
+            var b;
+            var c = function g() {
+                a = "FAIL";
+            };
+            a ? b |= c : b.p;
+        })();
+        console.log(a);
+    }
+    expect_stdout: "PASS"
+}