Skip to content

Commit

Permalink
fix corner case in reduce_vars (#5047)
Browse files Browse the repository at this point in the history
fixes #5046
  • Loading branch information
alexlamsl committed Jul 4, 2021
1 parent 972b9f0 commit f4ae267
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
8 changes: 1 addition & 7 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -1000,11 +1000,7 @@ merge(Compressor.prototype, {
arg.walk(tw);
if (arg instanceof AST_Spread) iife = false;
});
if (iife) {
exp.reduce_vars = reduce_iife;
} else {
exp.safe_ids = tw.safe_ids;
}
if (iife) exp.reduce_vars = reduce_iife;
exp.walk(tw);
if (iife) delete exp.reduce_vars;
return true;
Expand Down Expand Up @@ -1299,9 +1295,7 @@ merge(Compressor.prototype, {
node.expressions.forEach(function(exp) {
exp.walk(tw);
});
tag.safe_ids = tw.safe_ids;
tag.walk(tw);
delete tag.reduce_vars;
return true;
}
tag.walk(tw);
Expand Down
31 changes: 31 additions & 0 deletions test/compress/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6285,3 +6285,34 @@ issue_5036: {
}
expect_stdout: "PASS"
}

issue_5046: {
options = {
conditionals: true,
evaluate: true,
keep_fnames: true,
passes: 2,
reduce_vars: true,
side_effects: true,
toplevel: true,
}
input: {
var a = 0;
if (a)
0();
else
(function f() {
f;
return a = "PASS";
})();
console.log(a);
}
expect: {
var a = 0;
(a ? 0 : function f() {
return a = "PASS";
})();
console.log(a);
}
expect_stdout: "PASS"
}

0 comments on commit f4ae267

Please sign in to comment.