scan within IIFEs of assigned values (#2702)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 1 Jan 2018 17:24:23 +0000 (01:24 +0800)
committerGitHub <noreply@github.com>
Mon, 1 Jan 2018 17:24:23 +0000 (01:24 +0800)
fixes #2701

lib/compress.js
test/compress/dead-code.js

index ee80901..73cc9d7 100644 (file)
@@ -4913,9 +4913,8 @@ merge(Compressor.prototype, {
             if (reachable) return true;
             if (node instanceof AST_Scope && node !== self) {
                 var parent = scan_scope.parent();
-                if (!(parent instanceof AST_Call && parent.expression === node)) {
-                    node.walk(find_ref);
-                }
+                if (parent instanceof AST_Call && parent.expression === node) return;
+                node.walk(find_ref);
                 return true;
             }
         });
index 68ee4b1..32bb88e 100644 (file)
@@ -881,3 +881,31 @@ issue_2692: {
     }
     expect_stdout: "function"
 }
+
+issue_2701: {
+    options = {
+        dead_code: true,
+        inline: false,
+    }
+    input: {
+        function f(a) {
+            return a = function() {
+                return function() {
+                    return a;
+                };
+            }();
+        }
+        console.log(typeof f()());
+    }
+    expect: {
+        function f(a) {
+            return a = function() {
+                return function() {
+                    return a;
+                };
+            }();
+        }
+        console.log(typeof f()());
+    }
+    expect_stdout: "function"
+}