Skip to content

Commit 15b608f

Browse files
authored
fix corner case in inline (#5635)
fixes #5634
1 parent 7c52af0 commit 15b608f

File tree

2 files changed

+152
-1
lines changed

2 files changed

+152
-1
lines changed

Diff for: lib/compress.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13729,7 +13729,7 @@ Compressor.prototype.compress = function(node) {
1372913729
}));
1373013730
return !abort;
1373113731
};
13732-
} else if (in_await && !is_async(fn) || in_async_generator(scope)) {
13732+
} else if (in_await || is_async(fn) || in_async_generator(scope)) {
1373313733
verify_body = function(stat) {
1373413734
var abort = false;
1373513735
var find_return = new TreeWalker(function(node) {

Diff for: test/compress/awaits.js

+151
Original file line numberDiff line numberDiff line change
@@ -3229,3 +3229,154 @@ issue_5528_4: {
32293229
]
32303230
node_version: ">=8"
32313231
}
3232+
3233+
issue_5634_1: {
3234+
options = {
3235+
awaits: true,
3236+
inline: true,
3237+
side_effects: true,
3238+
}
3239+
input: {
3240+
var a = "foo";
3241+
(async function() {
3242+
(async function() {
3243+
try {
3244+
return {
3245+
then(resolve) {
3246+
console.log("bar");
3247+
resolve();
3248+
console.log("baz");
3249+
},
3250+
};
3251+
} finally {
3252+
a = "moo";
3253+
}
3254+
})();
3255+
})();
3256+
console.log(a);
3257+
}
3258+
expect: {
3259+
var a = "foo";
3260+
(async function() {
3261+
try {
3262+
return {
3263+
then(resolve) {
3264+
console.log("bar");
3265+
resolve();
3266+
console.log("baz");
3267+
},
3268+
};
3269+
} finally {
3270+
a = "moo";
3271+
}
3272+
})();
3273+
console.log(a);
3274+
}
3275+
expect_stdout: [
3276+
"moo",
3277+
"bar",
3278+
"baz",
3279+
]
3280+
node_version: ">=8"
3281+
}
3282+
3283+
issue_5634_2: {
3284+
options = {
3285+
inline: true,
3286+
}
3287+
input: {
3288+
var a = "foo";
3289+
(async function() {
3290+
await async function() {
3291+
try {
3292+
return {
3293+
then(resolve) {
3294+
console.log("bar");
3295+
resolve();
3296+
console.log("baz");
3297+
},
3298+
};
3299+
} finally {
3300+
a = "moo";
3301+
}
3302+
}();
3303+
})();
3304+
console.log(a);
3305+
}
3306+
expect: {
3307+
var a = "foo";
3308+
(async function() {
3309+
await async function() {
3310+
try {
3311+
return {
3312+
then(resolve) {
3313+
console.log("bar");
3314+
resolve();
3315+
console.log("baz");
3316+
},
3317+
};
3318+
} finally {
3319+
a = "moo";
3320+
}
3321+
}();
3322+
})();
3323+
console.log(a);
3324+
}
3325+
expect_stdout: [
3326+
"moo",
3327+
"bar",
3328+
"baz",
3329+
]
3330+
node_version: ">=8"
3331+
}
3332+
3333+
issue_5634_3: {
3334+
options = {
3335+
awaits: true,
3336+
inline: true,
3337+
}
3338+
input: {
3339+
var a = "foo";
3340+
(async function() {
3341+
return async function() {
3342+
try {
3343+
return {
3344+
then(resolve) {
3345+
console.log("bar");
3346+
resolve();
3347+
console.log("baz");
3348+
},
3349+
};
3350+
} finally {
3351+
a = "moo";
3352+
}
3353+
}();
3354+
})();
3355+
console.log(a);
3356+
}
3357+
expect: {
3358+
var a = "foo";
3359+
(async function() {
3360+
return async function() {
3361+
try {
3362+
return {
3363+
then(resolve) {
3364+
console.log("bar");
3365+
resolve();
3366+
console.log("baz");
3367+
},
3368+
};
3369+
} finally {
3370+
a = "moo";
3371+
}
3372+
}();
3373+
})();
3374+
console.log(a);
3375+
}
3376+
expect_stdout: [
3377+
"moo",
3378+
"bar",
3379+
"baz",
3380+
]
3381+
node_version: ">=8"
3382+
}

0 commit comments

Comments
 (0)