forked from babel/babel
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove one promise tick in yield* (tc39/ecma262#2819)
- Loading branch information
1 parent
a31fb6d
commit 6978c93
Showing
11 changed files
with
196 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* @minVersion 7.18.14 */ | ||
|
||
/* | ||
* 'kind' is an enum: | ||
* 0 => This yield was an await expression | ||
* 1 => This yield comes from yield* | ||
*/ | ||
export default function _OverloadYield(value, kind) { | ||
this.v = value; | ||
this.k = kind; | ||
} |
10 changes: 8 additions & 2 deletions
10
packages/babel-helpers/src/helpers/asyncGeneratorDelegate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* @minVersion 7.0.0-beta.0 */ | ||
|
||
import AwaitValue from "AwaitValue"; | ||
import OverloadYield from "OverloadYield"; | ||
|
||
export default function _awaitAsyncGenerator(value) { | ||
return new AwaitValue(value); | ||
return new OverloadYield(value, /* kind: await */ 0); | ||
} |
25 changes: 25 additions & 0 deletions
25
...lugin-proposal-async-generator-functions/test/fixtures/yield-star/ecma262-pr-2819/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// https://github.com/tc39/ecma262/pull/2819 | ||
|
||
let done = false; | ||
let inner = { | ||
[Symbol.asyncIterator]: () => ({ | ||
next() { | ||
if (done) { | ||
return Promise.resolve({ done: true }); | ||
} | ||
done = true; | ||
return Promise.resolve({ done: false, value: Promise.resolve(0) }); | ||
}, | ||
}), | ||
}; | ||
|
||
async function* outer() { | ||
yield* inner; | ||
} | ||
|
||
return (async function () { | ||
for await (let x of outer()) { | ||
expect(x).toBeInstanceOf(Promise); | ||
expect(await x).toBe(0); | ||
} | ||
})(); |
Oops, something went wrong.