Skip to content

Commit

Permalink
fix corner case in awaits (#4988)
Browse files Browse the repository at this point in the history
fixes #4987
  • Loading branch information
alexlamsl committed May 30, 2021
1 parent 23b9f36 commit 55a230d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,12 @@ merge(Compressor.prototype, {
}),
});
}
if (node instanceof AST_Lambda && node !== self) {
return node;
}
if (node instanceof AST_Block) {
if (node instanceof AST_Lambda) {
if (node !== self) return node;
} else if (insert === "awaits" && node instanceof AST_Try) {
if (node.bfinally) return node;
}
var index = node.body.length - 1;
if (index >= 0) {
node.body[index] = node.body[index].transform(tt);
Expand Down Expand Up @@ -7587,7 +7589,7 @@ merge(Compressor.prototype, {
});
}
if (async && compressor.option("awaits")) {
if (drop_body) exp.process_expression(true, function(node) {
if (drop_body) exp.process_expression("awaits", function(node) {
var body = node.body;
if (body instanceof AST_Await) {
if (is_primitive(compressor, body.expression)) {
Expand Down
32 changes: 32 additions & 0 deletions test/compress/awaits.js
Original file line number Diff line number Diff line change
Expand Up @@ -1726,3 +1726,35 @@ issue_4975: {
expect_stdout: "object"
node_version: ">=8"
}

issue_4987: {
options = {
awaits: true,
side_effects: true,
}
input: {
(async function() {
try {
await 42;
} finally {
console.log("foo");
}
})();
console.log("bar");
}
expect: {
(async function() {
try {
await 0;
} finally {
console.log("foo");
}
})();
console.log("bar");
}
expect_stdout: [
"bar",
"foo",
]
node_version: ">=8"
}

0 comments on commit 55a230d

Please sign in to comment.