Skip to content

Commit 58d997a

Browse files
authored
fix corner case in booleans & conditionals (#5696)
1 parent dabcc39 commit 58d997a

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

lib/compress.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11592,7 +11592,7 @@ Compressor.prototype.compress = function(node) {
1159211592

1159311593
function extract_lhs(node, compressor) {
1159411594
if (node instanceof AST_Assign) return is_lhs_read_only(node.left, compressor) ? node : node.left;
11595-
if (node instanceof AST_Sequence) return extract_lhs(node.tail_node());
11595+
if (node instanceof AST_Sequence) return extract_lhs(node.tail_node(), compressor);
1159611596
if (node instanceof AST_UnaryPrefix && UNARY_POSTFIX[node.operator]) {
1159711597
return is_lhs_read_only(node.expression, compressor) ? node : node.expression;
1159811598
}

test/compress/booleans.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -831,19 +831,36 @@ issue_5469: {
831831
expect_stdout: "undefined"
832832
}
833833

834-
issue_5694: {
834+
issue_5694_1: {
835835
options = {
836836
booleans: true,
837837
conditionals: true,
838838
}
839839
input: {
840-
var undefined;
840+
var Infinity;
841841
// Node.js v0.12~6 (vm): 42
842-
console.log((undefined = 42) && undefined);
842+
console.log((Infinity = 42) && Infinity);
843+
}
844+
expect: {
845+
var Infinity;
846+
console.log((Infinity = 42) && Infinity);
847+
}
848+
expect_stdout: true
849+
}
850+
851+
issue_5694_2: {
852+
options = {
853+
booleans: true,
854+
conditionals: true,
855+
}
856+
input: {
857+
var undefined;
858+
// Node.js v0.12~6 (vm): NaN
859+
console.log(("foo", ++undefined) || undefined);
843860
}
844861
expect: {
845862
var undefined;
846-
console.log((undefined = 42) && undefined);
863+
console.log(("foo", ++undefined) || undefined);
847864
}
848865
expect_stdout: true
849866
}

0 commit comments

Comments
 (0)