Skip to content

Commit 657d525

Browse files
authored
fix corner case in reduce_vars (#5099)
fixes #5098
1 parent 6a3fe9d commit 657d525

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lib/compress.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,10 @@ merge(Compressor.prototype, {
981981
if (fixed && !modified && !sym.in_arg && safe_to_assign(tw, d)) {
982982
push_ref(d, sym);
983983
mark(tw, d);
984-
if (d.single_use && left instanceof AST_Destructured) d.single_use = false;
984+
if (left instanceof AST_Destructured
985+
|| d.orig.length == 1 && d.orig[0] instanceof AST_SymbolDefun) {
986+
d.single_use = false;
987+
}
985988
tw.loop_ids[d.id] = tw.in_loop;
986989
mark_escaped(tw, d, sym.scope, node, right, 0, 1);
987990
sym.fixed = d.fixed = fixed;

test/compress/functions.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6535,3 +6535,33 @@ issue_5096_4: {
65356535
}
65366536
expect_stdout: "PASS"
65376537
}
6538+
6539+
issue_5098: {
6540+
options = {
6541+
reduce_vars: true,
6542+
unused: true,
6543+
}
6544+
input: {
6545+
(function(o) {
6546+
function f() {
6547+
f = console.log;
6548+
if (o.p++)
6549+
throw "FAIL";
6550+
f("PASS");
6551+
}
6552+
return f;
6553+
})({ p: 0 })();
6554+
}
6555+
expect: {
6556+
(function(o) {
6557+
function f() {
6558+
f = console.log;
6559+
if (o.p++)
6560+
throw "FAIL";
6561+
f("PASS");
6562+
}
6563+
return f;
6564+
})({ p: 0 })();
6565+
}
6566+
expect_stdout: "PASS"
6567+
}

0 commit comments

Comments
 (0)