Skip to content
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

Merged

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Feb 9, 2019

Q                       A
Fixed Issues?
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature? Maybe?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

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 when regenerator 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.

@nicolo-ribaudo nicolo-ribaudo added PR: Polish 💅 A type of pull request used for our changelog categories pkg: preset-env Spec: Async Functions labels Feb 9, 2019
@babel-bot
Copy link
Collaborator

babel-bot commented Feb 9, 2019

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/10670/

Copy link
Member

@danez danez left a 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

@nicolo-ribaudo
Copy link
Member Author

Unless I have a very strong passion for resolving merge conflicts 😛

@loganfsmyth
Copy link
Member

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.

@nicolo-ribaudo
Copy link
Member Author

regenerator hasn't always been very good at handling cases where ES6 syntax is used inside generators

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.

I'm just worried that this could introduce changes in behavior because various things could run in a different order.

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:
https://github.com/facebook/regenerator/blob/f44b30de0bad413e1256322004b63ca39ad8d75e/packages/regenerator-transform/src/visit.js#L19

@nicolo-ribaudo nicolo-ribaudo merged commit 8618447 into babel:master Nov 4, 2019
@nicolo-ribaudo nicolo-ribaudo deleted the preset-env-async-regenerator branch November 4, 2019 21:53
sodatea added a commit to vuejs/vue-cli that referenced this pull request Nov 26, 2019
maximerety added a commit to TankerHQ/sdk-js that referenced this pull request Dec 19, 2019
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Feb 3, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Feb 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: preset-env PR: Polish 💅 A type of pull request used for our changelog categories Spec: Async Functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants