-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
Bug Report
Current Behavior
When for await is used on a generator that uses yield* to delegate to another generator and we attempt to break out of the loop, the iteration stops but the code after yield* still runs. This is wrong and the native implementation in V8 doesn't have this problem.
This essentially means that with the code below, we get done:
0
'done'Input Code
Link to example repo
async function* inner() {
const ids = [0, 1, 2, 3];
for await (const id of ids) {
yield id;
}
}
async function* wrapper() {
yield* inner();
console.log('done');
}
const run = async() => {
for await (const id of wrapper()) {
console.log(id);
break;
}
};
run();Expected behavior/code
If you run the above code in the Chrome console, you get:
0This is the desired behavior (as implemented natively in V8). Since we are breaking out of the loop, the execution inside the generator must not continue.
Babel Configuration (.babelrc, package.json, cli command)
Please check the repo link above for more details.
babel.config.js
module.exports = (api) => {
api.cache(true);
return {
presets: [
[
'@babel/preset-env',
{
targets: {
node: '8.11.3'
}
}
]
]
}
}package.json (partial)
{
"scripts": {
"build": "babel ./src -d ./dist -s",
"start:dist": "node ./dist",
"start": "babel-node ./src"
},
"devDependencies": {
"@babel/cli": "^7.1.5",
"@babel/core": "^7.1.6",
"@babel/node": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.1.6"
}
}Environment
- Babel version(s): v7.1.6
- Node/npm version: Node 8.11.3/npm 6.4.1
- OS: OSX 10.13.6
- Monorepo: no
- How you are using Babel: cli