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

Always transform for-await in async functions[rebase of #6953]. #7446

Merged
merged 1 commit into from Mar 5, 2018
Merged

Always transform for-await in async functions[rebase of #6953]. #7446

merged 1 commit into from Mar 5, 2018

Conversation

Gvozd
Copy link
Contributor

@Gvozd Gvozd commented Feb 27, 2018

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

for-await was transformed in @babel/helper-remap-async-to-generator, which was called
by @babel/plugin-transform-async-to-generator and
@babel/plugin-proposal-async-generator-functions. This prevented for-await statements
in async functions to be transpiled if the transform-async-to-generator plugin was't
enabled.

This might be considered a breaking change, in case someone used for-await in async functions using just the async functions transform.

This PR is rebase(and fix merge conflicts) of #6953 on actual master

for-await was transformed in @babel/helper-remap-async-to-generator, which was called
by @babel/plugin-transform-async-to-generator and
@babel/plugin-proposal-async-generator-functions. This prevented for-await statements
in async functions to be transpiled if the transform-async-to-generator plugin was't
enabled.
@Gvozd
Copy link
Contributor Author

Gvozd commented Feb 27, 2018

@nicolo-ribaudo I've rebase your fix.
And I really need this fix)

@babel-bot
Copy link
Collaborator

babel-bot commented Feb 27, 2018

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

@nicolo-ribaudo
Copy link
Member

Thank you! 🙂

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories Spec: Async Generators labels Mar 4, 2018
@danez
Copy link
Member

danez commented Mar 4, 2018

Do I understand this correctly: To get the same result as before you need to have proposal-async-generator-functions (which name does not seem to make sense after this change?) and transform-async-to-generator active?

@nicolo-ribaudo
Copy link
Member

Before:

  • async function* () {} was parsed and transformed by proposal-async-generators
  • async function () {} was transformed by transform-async-to-generator
  • for await inside async function* () {} was parsed and transformed by proposal-async-generator
  • for await inside async function () {} was parsed by proposal-async-generators and transformed by transform-async-to-generator

After:

  • async function* () {} is parsed and transformed by proposal-async-generators
  • async function () {} is transformed by transform-async-to-generator
  • for await is parsed and transformed by proposal-async-generator

So to fully transpile this code yes, you need both the plugins:

async function fn() {
  for await (const x of gen()) {}
}

But it makes sense, because for await and asunc function* fn() {} are part of the same proposal and for await will almost always be used to iterate over async function* fn() {}

On the other hand, without this PR it is impossible to only transpile the for await statement in that code.

@danez
Copy link
Member

danez commented Mar 4, 2018

Thanks for the clarification.

@nicolo-ribaudo
Copy link
Member

I don't know if I should label this PR as a bug fix or as a breaking change 🤔

@nicolo-ribaudo nicolo-ribaudo added the PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release label Mar 5, 2018
@nicolo-ribaudo nicolo-ribaudo merged commit 653318b into babel:master Mar 5, 2018
@loilo
Copy link

loilo commented Mar 8, 2018

Is there any hint when this will go into @babel/preset-stage-3?

aminmarashi pushed a commit to aminmarashi/babel that referenced this pull request Mar 17, 2018
for-await was transformed in @babel/helper-remap-async-to-generator, which was
called by @babel/plugin-transform-async-to-generator and
@babel/plugin-proposal-async-generator-functions. This prevented for-await
statements in async functions to be transpiled if the
transform-async-to-generator plugin was't enabled.
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 5, 2019
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 PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release PR: Bug Fix 🐛 A type of pull request used for our changelog categories Spec: Async Generators
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants