New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
transform-async-generator-functions not transform for-await in async functions #4969
Comments
It looks like the logic for converting for-await loops is actually in remap-async-to-generator for some reason, which is a pain because it means that in order to use for-await in an async function you have to also convert them into generators. I might have a look this week into moving it into its own helper and make async-generator-functions use it. |
What's actually a Promise, in async iterators, is the the iterator result object itself, which is why new syntax, symbols, etc were required.
// _very_ incomplete sugar
for (
let iter = y[Symbol.asyncIterator](), step = await iter.next();
!step.done;
step = await iter.next()
) {
const x = step.value // note, no await here!
} |
@Jamesernator Does "transform-async-generator-functions" work well now? I test with '6.24.1', still do not work. And it seems it will transform 'for await' to 'generators' with an additional plugin 'transform-async-to-generator'. |
#7446 is merged. Should this issue be closed? |
@alexeyraspopov thanks! |
@existentialism, not sure about proper place to ask, but do you know what else should happen so the babel-preset-env will start supporting async generators (and object rest/spread I guess)? |
How do I 'get' this fix? My {
"plugins": [
"transform-object-rest-spread",
"transform-class-properties",
"transform-function-bind",
"syntax-async-generators",
"transform-async-generator-functions"
],
"presets": [
[
"env",
{
"targets": {
"node": "current"
}
}
]
],
"compact": false
} And package.json:
What versions do I have to bump? The fix is on npm, right? |
It's in Babel 7 beta. |
Input Code
Babel Configuration (.babelrc, package.json, cli command)
Expected Behavior
Both
bar()
andfor-await-of
infoo()
should be transformed.Current Behavior
for-await-of
infoo()
is not transformed.Possible Solution
As I understand,
for await (const x of y) { x }
is like a sugar of:for (const x of y) { await x }
(but cally[Symbol.asyncIterator]()
instead ofy[Symbol.iterator]()
)Maybe we can introduce a separate plugin
transform-for-await-of
.The text was updated successfully, but these errors were encountered: