fix corner case in `loops` & `unused` (#4083)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 28 Aug 2020 18:42:17 +0000 (19:42 +0100)
committerGitHub <noreply@github.com>
Fri, 28 Aug 2020 18:42:17 +0000 (02:42 +0800)
fixes #4082

lib/compress.js
test/compress/loops.js

index 90dd0f2..bab390c 100644 (file)
@@ -4800,7 +4800,7 @@ merge(Compressor.prototype, {
                 return true;
             }
             if (node instanceof AST_ForIn) {
-                if (!compressor.option("loops")) return;
+                if (!drop_vars || !compressor.option("loops")) return;
                 if (!is_empty(node.body)) return;
                 if (node.init.has_side_effects(compressor)) return;
                 node.object.walk(tw);
index 23d46de..e24b371 100644 (file)
@@ -985,3 +985,27 @@ issue_4075: {
     }
     expect_stdout: "PASS"
 }
+
+issue_4082: {
+    options = {
+        keep_fargs: "strict",
+        loops: true,
+        unused: true,
+    }
+    input: {
+        var a = "PASS";
+        (function(a) {
+            for (a in "foo")
+                var b;
+        })();
+        console.log(a);
+    }
+    expect: {
+        var a = "PASS";
+        (function(a) {
+            for (a in "foo");
+        })();
+        console.log(a);
+    }
+    expect_stdout: "PASS"
+}