regenerator
regenerator copied to clipboard
Only the first yield* expression is used by regenerator
Original issue submitted by @quasicomputational in https://github.com/babel/babel/issues/9535
Bug Report
Current Behavior
Only the first await yield*
is run, with the combiner
function exiting immediately after it completes.
When run with babel-node
:
$ babel-node index.js
0
1
2
Input Code
- REPL or Repo link if applicable:
const inner = async function*(n) {
yield n;
yield n + 1;
yield n + 2;
};
const combiner = async function*(n) {
await (yield* inner(0));
console.log("Halfway!");
await (yield* inner(10));
console.log("Done!");
};
const main = async function() {
const generator = combiner();
while (true) {
const res = await generator.next();
if (res.done) {
break;
} else {
console.log(res.value);
}
}
};
main();
Expected behavior/code
The inner
loop should be run twice. This is what happens when run natively:
$ node
0
1
2
Halfway!
10
11
12
Done!
Babel Configuration (.babelrc, package.json, cli command)
module.exports = {
"presets": [
[
"@babel/env",
{
"targets": {
"browsers": [
"node 11",
],
},
},
],
],
"plugins": [
"@babel/plugin-transform-regenerator",
[
"@babel/plugin-transform-runtime",
{
"regenerator": true,
},
],
],
};
{
"dependencies": {
"@babel/core": "^7.3.3",
"@babel/node": "^7.2.2",
"@babel/plugin-transform-regenerator": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/preset-env": "^7.3.1",
"@babel/runtime": "^7.3.1"
}
}
Environment
- Babel version(s): 7.3.3
- Node/npm version: 11
- OS: Debian stretch
- Monorepo: [e.g. yes/no/Lerna]
- How you are using Babel: [e.g.
cli
,register
,loader
]
Possible Solution
Additional context/Screenshots Add any other context about the problem here. If applicable, add screenshots to help explain.