Skip to content

Commit

Permalink
fix corner case in reduce_vars (#5099)
Browse files Browse the repository at this point in the history
fixes #5098
  • Loading branch information
alexlamsl committed Jul 23, 2021
1 parent 6a3fe9d commit 657d525
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,10 @@ merge(Compressor.prototype, {
if (fixed && !modified && !sym.in_arg && safe_to_assign(tw, d)) {
push_ref(d, sym);
mark(tw, d);
if (d.single_use && left instanceof AST_Destructured) d.single_use = false;
if (left instanceof AST_Destructured
|| d.orig.length == 1 && d.orig[0] instanceof AST_SymbolDefun) {
d.single_use = false;
}
tw.loop_ids[d.id] = tw.in_loop;
mark_escaped(tw, d, sym.scope, node, right, 0, 1);
sym.fixed = d.fixed = fixed;
Expand Down
30 changes: 30 additions & 0 deletions test/compress/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6535,3 +6535,33 @@ issue_5096_4: {
}
expect_stdout: "PASS"
}

issue_5098: {
options = {
reduce_vars: true,
unused: true,
}
input: {
(function(o) {
function f() {
f = console.log;
if (o.p++)
throw "FAIL";
f("PASS");
}
return f;
})({ p: 0 })();
}
expect: {
(function(o) {
function f() {
f = console.log;
if (o.p++)
throw "FAIL";
f("PASS");
}
return f;
})({ p: 0 })();
}
expect_stdout: "PASS"
}

0 comments on commit 657d525

Please sign in to comment.