Skip to content

Commit

Permalink
fix corner case in loops (#4565)
Browse files Browse the repository at this point in the history
fixes #4564
  • Loading branch information
alexlamsl committed Jan 17, 2021
1 parent 884ec4e commit e23a10f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -6169,7 +6169,7 @@ merge(Compressor.prototype, {
var def = sym.definition();
if (def.scope !== self) {
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);
return true;
Expand Down
30 changes: 30 additions & 0 deletions test/compress/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -1280,3 +1280,33 @@ issue_4355: {
}
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"
}
2 changes: 1 addition & 1 deletion test/reduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ function has_loopcontrol(body, loop, label) {
}

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) {
Expand Down

0 comments on commit e23a10f

Please sign in to comment.