fix corner case in loops & unused (#4241)

fixes #4240
This commit is contained in:
Alex Lam S.L
2020-10-24 06:33:48 +01:00
committed by GitHub
parent ff38d2471f
commit c5df8355ba
2 changed files with 33 additions and 1 deletions

View File

@@ -5182,7 +5182,7 @@ merge(Compressor.prototype, {
var def = sym.definition();
if (!def) return;
if (def.id in in_use_ids) return;
if (def.scope !== self && member(def, self.enclosed)) return;
if (def.scope !== self && self.find_variable(sym) === def) return;
log(sym, "Dropping unused loop variable {name}");
if (for_ins[def.id] === node) delete for_ins[def.id];
var body = [];

View File

@@ -1222,3 +1222,35 @@ do_continue: {
}
expect_stdout: "PASS"
}
issue_4240: {
options = {
loops: true,
reduce_funcs: true,
reduce_vars: true,
unused: true,
}
input: {
(function(a) {
function f() {
var o = { PASS: 42 };
for (a in o);
}
(function() {
if (f());
})();
console.log(a);
})();
}
expect: {
(function(a) {
(function() {
if (function() {
for (a in { PASS: 42 });
}());
})();
console.log(a);
})();
}
expect_stdout: "PASS"
}