aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/compress.js4
-rw-r--r--test/compress/loops.js22
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 213cead3..a1f3d50c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4677,7 +4677,9 @@ merge(Compressor.prototype, {
sym = sym.expression.tail_node();
}
var def = sym.definition();
- if (!def || def.id in in_use_ids) return;
+ if (!def) return;
+ if (def.scope !== self) return;
+ if (def.id in in_use_ids) return;
log(sym, "Dropping unused loop variable {name}");
var value = node.object.drop_side_effect_free(compressor);
if (!value) return in_list ? List.skip : make_node(AST_EmptyStatement, node);
diff --git a/test/compress/loops.js b/test/compress/loops.js
index 4a276b9e..23d46de1 100644
--- a/test/compress/loops.js
+++ b/test/compress/loops.js
@@ -963,3 +963,25 @@ issue_3634_2: {
}
expect_stdout: "1"
}
+
+issue_4075: {
+ options = {
+ loops: true,
+ unused: true,
+ }
+ input: {
+ var a = "FAIL";
+ (function() {
+ for (a in { PASS: 0 });
+ })()
+ console.log(a);
+ }
+ expect: {
+ var a = "FAIL";
+ (function() {
+ for (a in { PASS: 0 });
+ })()
+ console.log(a);
+ }
+ expect_stdout: "PASS"
+}