aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/compress.js2
-rw-r--r--test/compress/loops.js28
2 files changed, 29 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index bab390cf..2c21217e 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4682,8 +4682,8 @@ merge(Compressor.prototype, {
}
var def = sym.definition();
if (!def) return;
- if (def.scope !== self) return;
if (def.id in in_use_ids) return;
+ if (def.scope !== self && member(def, self.enclosed)) 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 e24b3712..878b77cb 100644
--- a/test/compress/loops.js
+++ b/test/compress/loops.js
@@ -1009,3 +1009,31 @@ issue_4082: {
}
expect_stdout: "PASS"
}
+
+issue_4084: {
+ options = {
+ keep_fargs: "strict",
+ loops: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ console.log(function() {
+ function f(a) {
+ var b = a++;
+ for (a in "foo");
+ }
+ f();
+ return typeof a;
+ }());
+ }
+ expect: {
+ console.log(function() {
+ (function() {
+ 0;
+ })();
+ return typeof a;
+ }());
+ }
+ expect_stdout: "undefined"
+}