fix corner case in loops & unused (#4083)

fixes #4082
This commit is contained in:
Alex Lam S.L
2020-08-28 19:42:17 +01:00
committed by GitHub
parent b1cc15e85b
commit f886b3fb2b
2 changed files with 25 additions and 1 deletions

View 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);

View 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"
}