Skip to content

Commit fada1a1

Browse files
authored
fix corner case in booleans (#5887)
fixes #5885
1 parent 722465b commit fada1a1

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lib/compress.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12119,7 +12119,11 @@ Compressor.prototype.compress = function(node) {
1211912119
var exprs = [];
1212012120
if (self.left.evaluate(compressor) instanceof AST_Node) exprs.push(self.left);
1212112121
if (self.right.evaluate(compressor) instanceof AST_Node) exprs.push(self.right);
12122-
if (exprs.length < 2) {
12122+
switch (exprs.length) {
12123+
case 0:
12124+
return make_node(AST_True, self).optimize(compressor);
12125+
case 1:
12126+
exprs[0] = exprs[0].clone();
1212312127
exprs.push(make_node(AST_True, self));
1212412128
return make_sequence(self, exprs).optimize(compressor);
1212512129
}

test/compress/functions.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8968,3 +8968,32 @@ issue_5851_2: {
89688968
"foo",
89698969
]
89708970
}
8971+
8972+
issue_5885: {
8973+
options = {
8974+
booleans: true,
8975+
evaluate: true,
8976+
inline: true,
8977+
reduce_vars: true,
8978+
side_effects: true,
8979+
toplevel: true,
8980+
unused: true,
8981+
}
8982+
input: {
8983+
var a;
8984+
f();
8985+
function f() {
8986+
return ++a + "foo";
8987+
}
8988+
console.log(a = f());
8989+
}
8990+
expect: {
8991+
var a;
8992+
f();
8993+
function f() {
8994+
return ++a + "foo";
8995+
}
8996+
console.log(a = f());
8997+
}
8998+
expect_stdout: "NaNfoo"
8999+
}

0 commit comments

Comments
 (0)