Skip to content

Commit

Permalink
fix corner case in inline (#5267)
Browse files Browse the repository at this point in the history
fixes #5266
  • Loading branch information
alexlamsl committed Jan 4, 2022
1 parent 3a3666a commit d46eb69
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/compress.js
Expand Up @@ -12898,8 +12898,8 @@ Compressor.prototype.compress = function(node) {
return cond.negate(compressor);
case "??":
return make_node(AST_Binary, self, {
operator: "===",
left: make_node(AST_Undefined, self).transform(compressor),
operator: "==",
left: make_node(AST_Null, self),
right: cond,
});
}
Expand Down
41 changes: 40 additions & 1 deletion test/compress/nullish.js
Expand Up @@ -274,7 +274,7 @@ inline_binary_nullish: {
})();
}
expect: {
if (void 0 === function() {
if (null == function() {
while (console.log("foo"));
}())
while (console.log("bar"));
Expand Down Expand Up @@ -304,3 +304,42 @@ issue_4679: {
expect_stdout: "PASS"
node_version: ">=14"
}

issue_5266: {
options = {
inline: true,
}
input: {
[
42,
null,
false,
void 0,
"FAIL",
].forEach(function (a) {
a ?? function() {
while (console.log(a));
}();
});
}
expect: {
[
42,
null,
false,
void 0,
"FAIL",
].forEach(function (a) {
if (null == a) {
while (console.log(a));
return;
} else
return;
});
}
expect_stdout: [
"null",
"undefined",
]
node_version: ">=14"
}

0 comments on commit d46eb69

Please sign in to comment.