Skip to content

Commit

Permalink
fix corner case in inline (#5635)
Browse files Browse the repository at this point in the history
fixes #5634
  • Loading branch information
alexlamsl authored Aug 29, 2022
1 parent 7c52af0 commit 15b608f
Show file tree
Hide file tree
Showing 2 changed files with 152 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 @@ -13729,7 +13729,7 @@ Compressor.prototype.compress = function(node) {
}));
return !abort;
};
} else if (in_await && !is_async(fn) || in_async_generator(scope)) {
} else if (in_await || is_async(fn) || in_async_generator(scope)) {
verify_body = function(stat) {
var abort = false;
var find_return = new TreeWalker(function(node) {
Expand Down
151 changes: 151 additions & 0 deletions test/compress/awaits.js
Original file line number Diff line number Diff line change
Expand Up @@ -3229,3 +3229,154 @@ issue_5528_4: {
]
node_version: ">=8"
}

issue_5634_1: {
options = {
awaits: true,
inline: true,
side_effects: true,
}
input: {
var a = "foo";
(async function() {
(async function() {
try {
return {
then(resolve) {
console.log("bar");
resolve();
console.log("baz");
},
};
} finally {
a = "moo";
}
})();
})();
console.log(a);
}
expect: {
var a = "foo";
(async function() {
try {
return {
then(resolve) {
console.log("bar");
resolve();
console.log("baz");
},
};
} finally {
a = "moo";
}
})();
console.log(a);
}
expect_stdout: [
"moo",
"bar",
"baz",
]
node_version: ">=8"
}

issue_5634_2: {
options = {
inline: true,
}
input: {
var a = "foo";
(async function() {
await async function() {
try {
return {
then(resolve) {
console.log("bar");
resolve();
console.log("baz");
},
};
} finally {
a = "moo";
}
}();
})();
console.log(a);
}
expect: {
var a = "foo";
(async function() {
await async function() {
try {
return {
then(resolve) {
console.log("bar");
resolve();
console.log("baz");
},
};
} finally {
a = "moo";
}
}();
})();
console.log(a);
}
expect_stdout: [
"moo",
"bar",
"baz",
]
node_version: ">=8"
}

issue_5634_3: {
options = {
awaits: true,
inline: true,
}
input: {
var a = "foo";
(async function() {
return async function() {
try {
return {
then(resolve) {
console.log("bar");
resolve();
console.log("baz");
},
};
} finally {
a = "moo";
}
}();
})();
console.log(a);
}
expect: {
var a = "foo";
(async function() {
return async function() {
try {
return {
then(resolve) {
console.log("bar");
resolve();
console.log("baz");
},
};
} finally {
a = "moo";
}
}();
})();
console.log(a);
}
expect_stdout: [
"moo",
"bar",
"baz",
]
node_version: ">=8"
}

0 comments on commit 15b608f

Please sign in to comment.