Skip to content

Commit

Permalink
fix corner case in awaits (#5160)
Browse files Browse the repository at this point in the history
fixes #5159
  • Loading branch information
alexlamsl authored Oct 31, 2021
1 parent eb93d92 commit a841d45
Show file tree
Hide file tree
Showing 2 changed files with 70 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 && member(node, parent.body)) {
if (parent instanceof AST_Try && (parent.bfinally || parent.bcatch) !== node) {
drop = false;
break;
}
Expand Down
69 changes: 69 additions & 0 deletions test/compress/awaits.js
Original file line number Diff line number Diff line change
Expand Up @@ -2143,3 +2143,72 @@ issue_5157_promise: {
expect_stdout: "PASS"
node_version: ">=8"
}

issue_5159_1: {
options = {
awaits: true,
side_effects: true,
}
input: {
(async function() {
try {
throw "foo";
} catch (e) {
return await "bar";
} finally {
console.log("baz");
}
})().catch(console.log).then(console.log);
console.log("moo");
}
expect: {
(async function() {
try {
throw "foo";
} catch (e) {
return await "bar";
} finally {
console.log("baz");
}
})().catch(console.log).then(console.log);
console.log("moo");
}
expect_stdout: [
"moo",
"baz",
"bar",
]
node_version: ">=8"
}

issue_5159_2: {
options = {
awaits: true,
side_effects: true,
}
input: {
(async function() {
try {
throw "foo";
} catch (e) {
return await "bar";
}
})().catch(console.log).then(console.log);
console.log("baz");
}
expect: {
(async function() {
try {
throw "foo";
} catch (e) {
return "bar";
}
})().catch(console.log).then(console.log);
console.log("baz");
}
expect_stdout: [
"baz",
"bar",
]
node_version: ">=8"
}

0 comments on commit a841d45

Please sign in to comment.