From 140e4e0da881e2e92fad217586711aeb2fe6c274 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 3 Oct 2022 01:01:56 +0100 Subject: [PATCH] fix corner case in `inline` (#5693) fixes #5692 --- lib/compress.js | 5 +++- test/compress/awaits.js | 58 ++++++++++++++++++++++++++++++++++++++ test/compress/functions.js | 21 ++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 0c2a7e27f3..ea65992cd4 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -13888,7 +13888,10 @@ Compressor.prototype.compress = function(node) { var abort = false; stat.walk(new TreeWalker(function(node) { if (abort) return true; - if (async && node instanceof AST_Await || node instanceof AST_Return) return abort = true; + if (async && (node instanceof AST_Await || node instanceof AST_ForAwaitOf) + || node instanceof AST_Return) { + return abort = true; + } if (node instanceof AST_Scope) return true; })); return !abort; diff --git a/test/compress/awaits.js b/test/compress/awaits.js index 2e1142cb23..f1d3628ccd 100644 --- a/test/compress/awaits.js +++ b/test/compress/awaits.js @@ -3540,3 +3540,61 @@ issue_5634_3_side_effects: { ] node_version: ">=8" } + +issue_5692_1: { + options = { + awaits: true, + inline: true, + } + input: { + (async function() { + (async function() { + for await (var k of []); + })(); + console.log("foo"); + })(); + console.log("bar"); + } + expect: { + (async function() { + (async function() { + for await (var k of []); + })(); + console.log("foo"); + })(); + console.log("bar"); + } + expect_stdout: [ + "foo", + "bar", + ] + node_version: ">=10" +} + +issue_5692_2: { + options = { + awaits: true, + inline: true, + } + input: { + (async function() { + (async function() { + for (var k of []); + })(); + console.log("foo"); + })(); + console.log("bar"); + } + expect: { + (async function() { + for (var k of []); + console.log("foo"); + })(); + console.log("bar"); + } + expect_stdout: [ + "foo", + "bar", + ] + node_version: ">=8" +} diff --git a/test/compress/functions.js b/test/compress/functions.js index 7dada302cd..f97e750ee4 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -8719,3 +8719,24 @@ single_use_inline_collision: { } expect_stdout: "PASS" } + +issue_5692: { + options = { + inline: true, + } + input: { + (function() { + while (console.log("PASS")) + if (console) + return; + })(); + } + expect: { + (function() { + while (console.log("PASS")) + if (console) + return; + })(); + } + expect_stdout: "PASS" +}