-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
[preset-env] Don't use async-to-generator when already using regenerator #9481
[preset-env] Don't use async-to-generator when already using regenerator #9481
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/10670/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have merged this before corejs 3 :D
lgtm
Unless I have a very strong passion for resolving merge conflicts 😛 |
I think we should be careful with this. It seems like a pretty large change in expectations, and regenerator hasn't always been very good at handling cases where ES6 syntax is used inside generators. I'm just worried that this could introduce changes in behavior because various things could run in a different order. |
This doesn't change with this PR. Consider this code: async function fn() {
const { foo } = await syntaxRegeneratorDoesNotUnderstand();
} with this PR, it would be directly passed to regenerator (which would probably break). Without this PR, that code would be first transformed to _asyncToGenerator(function* fn() {
const { foo } = yield syntaxRegeneratorDoesNotUnderstand();
}); and then passed to regenerator, which would have broken anyway.
Regenerator transforms functions on exit, so I think that it will always run after that the function body (wether it is still an async function or it has become a generator function) has been transformed: |
bf3fd50
to
51e93d3
Compare
51e93d3
to
f087c3f
Compare
The biggest change is in babel: babel/babel#9481
Since regenerator handles async functions, there is no need to load an additional transform. You can see the benefits at f087c3f.
async-to-generator
will still be loaded whenregenerator
is not needed.NOTE: It would be better to also transform async generators only using regenerator when possible, but we can't do that because regenerator doesn't support
for await
.