Wait the correct number of ticks on nested await (#13961)

This commit is contained in:
Nicolò Ribaudo 2021-11-14 02:02:35 +01:00 committed by GitHub
parent 54c539ecc1
commit d16f8111ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 5 deletions

View File

@ -19,11 +19,6 @@ const awaitVisitor = {
AwaitExpression(path, { wrapAwait }) {
const argument = path.get("argument");
if (path.parentPath.isYieldExpression()) {
path.replaceWith(argument.node);
return;
}
path.replaceWith(
yieldExpression(
wrapAwait

View File

@ -0,0 +1,20 @@
const log = [];
const p1 = (async function () {
log.push(1);
await await null;
log.push(2);
})();
const p2 = (async function () {
log.push(3);
await null;
log.push(4);
})();
log.push(5);
const p3 = Promise.resolve().then(() => log.push(6)).then(() => log.push(7));
return Promise.all([p1, p2, p3]).then(() => {
expect(log).toEqual([1, 3, 5, 4, 6, 2, 7]);
});

View File

@ -0,0 +1,3 @@
async function fn() {
await await 1;
}

View File

@ -0,0 +1,5 @@
{
"parserOpts": {
"allowReturnOutsideFunction": true
}
}

View File

@ -0,0 +1,10 @@
function fn() {
return _fn.apply(this, arguments);
}
function _fn() {
_fn = babelHelpers.asyncToGenerator(function* () {
yield yield 1;
});
return _fn.apply(this, arguments);
}