From 27aa85f84bc634430d76f54b9acedbb0b5c3ea57 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 18 May 2022 23:39:20 +0100 Subject: [PATCH] fix corner cases in `merge_vars` (#5457) fixes #5456 --- lib/compress.js | 2 +- test/compress/awaits.js | 46 +++++++++++++++++++++++++++++++++++++++-- test/compress/yields.js | 46 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 89 insertions(+), 5 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 2d8fe36a..4262cee1 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6184,7 +6184,7 @@ Compressor.prototype.compress = function(node) { } if (node instanceof AST_Scope) { var in_iife = false; - if (node instanceof AST_LambdaExpression && !node.name) { + if (node instanceof AST_LambdaExpression && !node.name && !is_async(node) && !is_generator(node)) { var parent = tw.parent(); in_iife = parent && parent.TYPE == "Call" && parent.expression === node; } diff --git a/test/compress/awaits.js b/test/compress/awaits.js index 55951fa4..2447b390 100644 --- a/test/compress/awaits.js +++ b/test/compress/awaits.js @@ -1748,8 +1748,8 @@ issue_4454_2: { expect: { function f(a) { (async function(c = console.log(a)) {})(); - var a = 42..toString(); - console.log(a); + var b = 42..toString(); + console.log(b); } f("PASS"); } @@ -2959,3 +2959,45 @@ issue_5305_3: { expect_stdout: "PASS" node_version: ">=8" } + +issue_5456: { + options = { + inline: true, + merge_vars: true, + } + input: { + var a = true; + (function() { + (function(b, c) { + var d = async function() { + c = await null; + }(); + var e = function() { + if (c) + console.log(typeof d); + while (b); + }(); + })(function(i) { + return console.log("foo") && i; + }(a)); + })(); + } + expect: { + var a = true; + (function() { + b = (i = a, console.log("foo") && i), + i = async function() { + c = await null; + }(), + e = function() { + if (c) console.log(typeof i); + while (b); + }(), + void 0; + var b, c, i, e; + var i; + })(); + } + expect_stdout: "foo" + node_version: ">=8" +} diff --git a/test/compress/yields.js b/test/compress/yields.js index 2e1aab56..0ccfaf12 100644 --- a/test/compress/yields.js +++ b/test/compress/yields.js @@ -978,8 +978,8 @@ issue_4454_2: { expect: { function f(a) { (function*(c = console.log(a)) {})(); - var a = 42..toString(); - console.log(a); + var b = 42..toString(); + console.log(b); } f("PASS"); } @@ -1547,3 +1547,45 @@ issue_5425: { expect_stdout: "PASS undefined" node_version: ">=4" } + +issue_5456: { + options = { + inline: true, + merge_vars: true, + } + input: { + var a = true; + (function() { + (function(b, c) { + var d = function*() { + c = null; + }(); + var e = function() { + if (c) + console.log(typeof d); + while (b); + }(); + })(function(i) { + return console.log("foo") && i; + }(a)); + })(); + } + expect: { + var a = true; + (function() { + b = (i = a, console.log("foo") && i), + i = function*() { + c = null; + }(), + e = function() { + if (c) console.log(typeof i); + while (b); + }(), + void 0; + var b, c, i, e; + var i; + })(); + } + expect_stdout: "foo" + node_version: ">=4" +}