Skip to content

Commit

Permalink
fix corner case in booleans (#5887)
Browse files Browse the repository at this point in the history
fixes #5885
  • Loading branch information
alexlamsl committed Jul 15, 2024
1 parent 722465b commit fada1a1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -12119,7 +12119,11 @@ Compressor.prototype.compress = function(node) {
var exprs = [];
if (self.left.evaluate(compressor) instanceof AST_Node) exprs.push(self.left);
if (self.right.evaluate(compressor) instanceof AST_Node) exprs.push(self.right);
if (exprs.length < 2) {
switch (exprs.length) {
case 0:
return make_node(AST_True, self).optimize(compressor);
case 1:
exprs[0] = exprs[0].clone();
exprs.push(make_node(AST_True, self));
return make_sequence(self, exprs).optimize(compressor);
}
Expand Down
29 changes: 29 additions & 0 deletions test/compress/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8968,3 +8968,32 @@ issue_5851_2: {
"foo",
]
}

issue_5885: {
options = {
booleans: true,
evaluate: true,
inline: true,
reduce_vars: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
var a;
f();
function f() {
return ++a + "foo";
}
console.log(a = f());
}
expect: {
var a;
f();
function f() {
return ++a + "foo";
}
console.log(a = f());
}
expect_stdout: "NaNfoo"
}

0 comments on commit fada1a1

Please sign in to comment.