Skip to content

Commit

Permalink
fix corner case in awaits (#5158)
Browse files Browse the repository at this point in the history
fixes #5157
  • Loading branch information
alexlamsl committed Oct 29, 2021
1 parent a0250ec commit eb93d92
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
97 changes: 97 additions & 0 deletions test/compress/awaits.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit eb93d92

Please sign in to comment.