diff --git a/lib/compress.js b/lib/compress.js index 7d1e6fd6..225fc744 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -10334,7 +10334,7 @@ merge(Compressor.prototype, { do { node = parent; parent = compressor.parent(level++); - if (parent instanceof AST_Try && parent.bfinally && parent.bfinally !== node) { + if (parent instanceof AST_Try && member(node, parent.body)) { drop = false; break; } diff --git a/test/compress/awaits.js b/test/compress/awaits.js index 0a7ae648..a3b55b12 100644 --- a/test/compress/awaits.js +++ b/test/compress/awaits.js @@ -2046,3 +2046,100 @@ issue_5070: { expect_stdout: "PASS" node_version: ">=10" } + +issue_5157_async_function: { + options = { + awaits: true, + side_effects: true, + } + input: { + async function f() { + throw "FAIL"; + } + (async function() { + try { + return await f(); + } catch (e) { + return "PASS"; + } + })().then(console.log); + } + expect: { + async function f() { + throw "FAIL"; + } + (async function() { + try { + return await f(); + } catch (e) { + return "PASS"; + } + })().then(console.log); + } + expect_stdout: "PASS" + node_version: ">=8" +} + +issue_5157_async_iife: { + options = { + awaits: true, + side_effects: true, + } + input: { + (async function() { + try { + return await async function() { + throw "FAIL"; + }(); + } catch (e) { + return "PASS"; + } + })().then(console.log); + } + expect: { + (async function() { + try { + return await async function() { + throw "FAIL"; + }(); + } catch (e) { + return "PASS"; + } + })().then(console.log); + } + expect_stdout: "PASS" + node_version: ">=8" +} + +issue_5157_promise: { + options = { + awaits: true, + side_effects: true, + } + input: { + var p = new Promise(function(resolve, reject) { + reject("FAIL"); + }); + (async function() { + try { + return await p; + } catch (e) { + return "PASS"; + } + })().then(console.log); + } + expect: { + var p = new Promise(function(resolve, reject) { + reject("FAIL"); + }); + (async function() { + try { + return await p; + } catch (e) { + return "PASS"; + } + })().then(console.log); + } + expect_stdout: "PASS" + node_version: ">=8" +}