From d46eb69320914dd8f1b42baf6bb95432364bcf90 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Tue, 4 Jan 2022 20:25:48 +0000 Subject: [PATCH] fix corner case in `inline` (#5267) fixes #5266 --- lib/compress.js | 4 ++-- test/compress/nullish.js | 41 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 87e0f964..9320d5a7 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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, }); } diff --git a/test/compress/nullish.js b/test/compress/nullish.js index be9c752d..b141d10b 100644 --- a/test/compress/nullish.js +++ b/test/compress/nullish.js @@ -274,7 +274,7 @@ inline_binary_nullish: { })(); } expect: { - if (void 0 === function() { + if (null == function() { while (console.log("foo")); }()) while (console.log("bar")); @@ -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" +}