aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-05-30 06:40:13 +0100
committerGitHub <noreply@github.com>2021-05-30 13:40:13 +0800
commit55a230daa84a004058d8cde0e15543bb2647dc3c (patch)
tree7bea0b57bc35cebbc20717fb54ec03ea8dfed92b
parent23b9f36bd83e95c36a12059546098f10452b56ba (diff)
downloadtracifyjs-55a230daa84a004058d8cde0e15543bb2647dc3c.tar.gz
tracifyjs-55a230daa84a004058d8cde0e15543bb2647dc3c.zip
fix corner case in `awaits` (#4988)
fixes #4987
-rw-r--r--lib/compress.js10
-rw-r--r--test/compress/awaits.js32
2 files changed, 38 insertions, 4 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 73f78aff..34d36a0c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -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);
@@ -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)) {
diff --git a/test/compress/awaits.js b/test/compress/awaits.js
index 612cf8b5..28558bd2 100644
--- a/test/compress/awaits.js
+++ b/test/compress/awaits.js
@@ -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"
+}