Skip to content

Commit 140e4e0

Browse files
authored
fix corner case in inline (#5693)
fixes #5692
1 parent 80fc862 commit 140e4e0

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

Diff for: lib/compress.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -13888,7 +13888,10 @@ Compressor.prototype.compress = function(node) {
1388813888
var abort = false;
1388913889
stat.walk(new TreeWalker(function(node) {
1389013890
if (abort) return true;
13891-
if (async && node instanceof AST_Await || node instanceof AST_Return) return abort = true;
13891+
if (async && (node instanceof AST_Await || node instanceof AST_ForAwaitOf)
13892+
|| node instanceof AST_Return) {
13893+
return abort = true;
13894+
}
1389213895
if (node instanceof AST_Scope) return true;
1389313896
}));
1389413897
return !abort;

Diff for: test/compress/awaits.js

+58
Original file line numberDiff line numberDiff line change
@@ -3540,3 +3540,61 @@ issue_5634_3_side_effects: {
35403540
]
35413541
node_version: ">=8"
35423542
}
3543+
3544+
issue_5692_1: {
3545+
options = {
3546+
awaits: true,
3547+
inline: true,
3548+
}
3549+
input: {
3550+
(async function() {
3551+
(async function() {
3552+
for await (var k of []);
3553+
})();
3554+
console.log("foo");
3555+
})();
3556+
console.log("bar");
3557+
}
3558+
expect: {
3559+
(async function() {
3560+
(async function() {
3561+
for await (var k of []);
3562+
})();
3563+
console.log("foo");
3564+
})();
3565+
console.log("bar");
3566+
}
3567+
expect_stdout: [
3568+
"foo",
3569+
"bar",
3570+
]
3571+
node_version: ">=10"
3572+
}
3573+
3574+
issue_5692_2: {
3575+
options = {
3576+
awaits: true,
3577+
inline: true,
3578+
}
3579+
input: {
3580+
(async function() {
3581+
(async function() {
3582+
for (var k of []);
3583+
})();
3584+
console.log("foo");
3585+
})();
3586+
console.log("bar");
3587+
}
3588+
expect: {
3589+
(async function() {
3590+
for (var k of []);
3591+
console.log("foo");
3592+
})();
3593+
console.log("bar");
3594+
}
3595+
expect_stdout: [
3596+
"foo",
3597+
"bar",
3598+
]
3599+
node_version: ">=8"
3600+
}

Diff for: test/compress/functions.js

+21
Original file line numberDiff line numberDiff line change
@@ -8719,3 +8719,24 @@ single_use_inline_collision: {
87198719
}
87208720
expect_stdout: "PASS"
87218721
}
8722+
8723+
issue_5692: {
8724+
options = {
8725+
inline: true,
8726+
}
8727+
input: {
8728+
(function() {
8729+
while (console.log("PASS"))
8730+
if (console)
8731+
return;
8732+
})();
8733+
}
8734+
expect: {
8735+
(function() {
8736+
while (console.log("PASS"))
8737+
if (console)
8738+
return;
8739+
})();
8740+
}
8741+
expect_stdout: "PASS"
8742+
}

0 commit comments

Comments
 (0)