From 313e4974a4a58750c06ad990dfd3e0eeabaf6c5c Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 21 Feb 2022 03:31:29 +0000 Subject: [PATCH] fix corner case in `inline` (#5367) fixes #5366 --- lib/compress.js | 7 +++++-- test/compress/functions.js | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index c9ca15ebf5..3e5e9194b7 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -13454,8 +13454,11 @@ Compressor.prototype.compress = function(node) { inlined = inlined.try_inline(compressor, scope, true, in_loop); if (inlined) { this.init = null; - inlined.body.push(this); - return inlined; + if (inlined instanceof AST_BlockStatement) { + inlined.body.push(this); + return inlined; + } + return make_node(AST_BlockStatement, inlined, { body: [ inlined, this ] }); } } return body && this; diff --git a/test/compress/functions.js b/test/compress/functions.js index 75131fcdcb..5204df6690 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -8207,3 +8207,24 @@ issue_5332_2: { } expect_stdout: "NaN" } + +issue_5366: { + options = { + inline: true, + } + input: { + for (console.log("foo") || function() { + while (console.log("bar")); + }(); console.log("baz") ;); + } + expect: { + if (!console.log("foo")) + while (console.log("bar")); + for (;console.log("baz");); + } + expect_stdout: [ + "foo", + "bar", + "baz", + ] +}