fix corner case in loops (#4565)

fixes #4564
This commit is contained in:
Alex Lam S.L
2021-01-17 22:36:59 +00:00
committed by GitHub
parent 884ec4e8a5
commit e23a10f7f9
3 changed files with 32 additions and 2 deletions

View File

@@ -6169,7 +6169,7 @@ merge(Compressor.prototype, {
var def = sym.definition(); var def = sym.definition();
if (def.scope !== self) { if (def.scope !== self) {
var d = find_variable(sym.name); var d = find_variable(sym.name);
if ((d && d.redefined() || d) === def) return; if (d === def || d && d.redefined() === def) return;
} }
node.object.walk(tw); node.object.walk(tw);
return true; return true;

View File

@@ -1280,3 +1280,33 @@ issue_4355: {
} }
expect_stdout: "PASS" expect_stdout: "PASS"
} }
issue_4564: {
options = {
loops: true,
unused: true,
}
input: {
try {
throw null;
} catch (a) {
var a;
(function() {
for (a in "foo");
})();
console.log(a);
}
}
expect: {
try {
throw null;
} catch (a) {
var a;
(function() {
for (a in "foo");
})();
console.log(a);
}
}
expect_stdout: "2"
}

View File

@@ -666,7 +666,7 @@ function has_loopcontrol(body, loop, label) {
} }
function is_error(result) { function is_error(result) {
return typeof result == "object" && typeof result.name == "string" && typeof result.message == "string"; return result && typeof result.name == "string" && typeof result.message == "string";
} }
function is_timed_out(result) { function is_timed_out(result) {