-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Closed
Copy link
Labels
Spec: Async GeneratorsoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issue
Description
💻
- Would you like to work on a fix?
How are you using Babel?
Other (Next.js, Gatsby, vue-cli, ...)
Input code
let resolve;
let promise = new Promise((r) => (resolve = r));
let iterable = {
[Symbol.asyncIterator]() {
return {
next() {
return promise;
},
};
},
};
(async () => {
for await (let value of iterable) {
console.log(value);
}
// let iterator = iterable[Symbol.asyncIterator]();
// while (true) {
// let result = await http://iterator.next();
// if (result.done) {
// break;
// }
// console.log(result.value);
// }
})();
(async function () {
for (let v of [0, 1]) {
await null;
let oldresolve = resolve;
promise = new Promise((r) => (resolve = r));
oldresolve({ value: v, done: false });
}
resolve({ value: undefined, done: true });
})();
Configuration file name
No response
Configuration
I think it's this? But you just need any configuration that correctly loads regenerator runtime and transpiles async functions. I tried to load babel-plugin-transform-runtime
or something to make it load in the REPL but the REPL just showed error messages, sorry.
Please set target to ie 11
.
{
"presets": ["@babel/preset-typescript", "@parcel/babel-preset-env"],
"plugins": [
["@parcel/babel-plugin-transform-runtime"],
["@babel/plugin-proposal-private-methods", { "loose": true }],
["@babel/plugin-proposal-class-properties", { "loose": true }],
],
};
Current and expected behavior
Running the untranspiled code yields this output:
0
1
Running the transpiled code yields this output:
0
Environment
- Babel 7.14.5 (@babel/core 7.14.6)
- Node v16.3.0
- npm 7.15.1
- macOS 10.15.7 (19H1217)
Possible solution
Make the transpiled code behave/output the same as the untranspiled code.
Additional context
If you replace the for await
loop with the commented out while loop the transpiled code behaves as expected.
Kudos to @mischnic for simplified repro code.
Metadata
Metadata
Assignees
Labels
Spec: Async GeneratorsoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issue