Skip to content

Commit d16f811

Browse files
Wait the correct number of ticks on nested await (#13961)
1 parent 54c539e commit d16f811

5 files changed

Lines changed: 38 additions & 5 deletions

File tree

packages/babel-helper-remap-async-to-generator/src/index.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ const awaitVisitor = {
1919
AwaitExpression(path, { wrapAwait }) {
2020
const argument = path.get("argument");
2121

22-
if (path.parentPath.isYieldExpression()) {
23-
path.replaceWith(argument.node);
24-
return;
25-
}
26-
2722
path.replaceWith(
2823
yieldExpression(
2924
wrapAwait
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const log = [];
2+
3+
const p1 = (async function () {
4+
log.push(1);
5+
await await null;
6+
log.push(2);
7+
})();
8+
9+
const p2 = (async function () {
10+
log.push(3);
11+
await null;
12+
log.push(4);
13+
})();
14+
15+
log.push(5);
16+
const p3 = Promise.resolve().then(() => log.push(6)).then(() => log.push(7));
17+
18+
return Promise.all([p1, p2, p3]).then(() => {
19+
expect(log).toEqual([1, 3, 5, 4, 6, 2, 7]);
20+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
async function fn() {
2+
await await 1;
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"parserOpts": {
3+
"allowReturnOutsideFunction": true
4+
}
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function fn() {
2+
return _fn.apply(this, arguments);
3+
}
4+
5+
function _fn() {
6+
_fn = babelHelpers.asyncToGenerator(function* () {
7+
yield yield 1;
8+
});
9+
return _fn.apply(this, arguments);
10+
}

0 commit comments

Comments
 (0)