Skip to content

Commit

Permalink
Wait the correct number of ticks on nested await (#13961)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Nov 14, 2021
1 parent 54c539e commit d16f811
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
5 changes: 0 additions & 5 deletions packages/babel-helper-remap-async-to-generator/src/index.js
Expand Up @@ -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
Expand Down
@@ -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]);
});
@@ -0,0 +1,3 @@
async function fn() {
await await 1;
}
@@ -0,0 +1,5 @@
{
"parserOpts": {
"allowReturnOutsideFunction": true
}
}
@@ -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);
}

0 comments on commit d16f811

Please sign in to comment.