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

@babel-bot

This comment has been minimized.

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/

@danez
danez approved these changes Mar 26, 2019
Copy link
Member

danez left a comment

We should have merged this before corejs 3 :D

lgtm

@nicolo-ribaudo

This comment has been minimized.

Copy link
Member Author

nicolo-ribaudo commented Mar 26, 2019

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

@loganfsmyth

This comment has been minimized.

Copy link
Member

loganfsmyth commented Mar 26, 2019

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

This comment has been minimized.

Copy link
Member Author

nicolo-ribaudo commented Mar 26, 2019

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 force-pushed the nicolo-ribaudo:preset-env-async-regenerator branch from bf3fd50 to 51e93d3 Apr 4, 2019
@nicolo-ribaudo nicolo-ribaudo force-pushed the nicolo-ribaudo:preset-env-async-regenerator branch from 51e93d3 to f087c3f Oct 17, 2019
@JLHwung JLHwung self-requested a review Nov 4, 2019
@JLHwung
JLHwung approved these changes Nov 4, 2019
@nicolo-ribaudo nicolo-ribaudo merged commit 8618447 into babel:master Nov 4, 2019
4 checks passed
4 checks passed
Travis CI - Pull Request Build Passed
Details
buildsize No significant change
Details
ci/circleci: test Your tests passed on CircleCI!
Details
codecov/project 88.15% (target 80%)
Details
@nicolo-ribaudo nicolo-ribaudo deleted the nicolo-ribaudo:preset-env-async-regenerator branch Nov 4, 2019
sodatea added a commit to vuejs/vue-cli that referenced this pull request Nov 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.