fix corner case in `ie8` (#4251)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 30 Oct 2020 03:06:31 +0000 (03:06 +0000)
committerGitHub <noreply@github.com>
Fri, 30 Oct 2020 03:06:31 +0000 (11:06 +0800)
fixes #4250

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

index 0b6ad85..e8c8801 100644 (file)
@@ -5200,7 +5200,10 @@ merge(Compressor.prototype, {
                 var def = sym.definition();
                 if (!def) return;
                 if (def.id in in_use_ids) return;
-                if (def.scope !== self && self.find_variable(sym) === def) return;
+                if (def.scope !== self) {
+                    var d = self.find_variable(sym);
+                    if ((d && d.redefined() || d) === def) return;
+                }
                 log(sym, "Dropping unused loop variable {name}");
                 if (for_ins[def.id] === node) delete for_ins[def.id];
                 var body = [];
index 2a7dace..c5b8b15 100644 (file)
@@ -2877,3 +2877,30 @@ issue_4235: {
     }
     expect_stdout: "undefined"
 }
+
+issue_4250: {
+    options = {
+        ie8: true,
+        loops: true,
+        unused: true,
+    }
+    input: {
+        console.log(function f() {
+            (function() {
+                for (f in "f");
+            })();
+            return f;
+            var f;
+        }());
+    }
+    expect: {
+        console.log(function f() {
+            (function() {
+                for (f in "f");
+            })();
+            return f;
+            var f;
+        }());
+    }
+    expect_stdout: "0"
+}