[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/ |
danez
left a comment
There was a problem hiding this comment.
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-generatorwill still be loaded whenregeneratoris 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.