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 retain lines for async arrow #11836

Merged
merged 6 commits into from Jul 15, 2020
Merged

Conversation

cwohlman
Copy link
Contributor

@cwohlman cwohlman commented Jul 14, 2020

First stab at fixing #11830, fixes the bug but has other issues.

Q                       A
Fixed Issues Fixes #11830
Patch: Bug Fix? Yes
Major: Breaking Change? No - Although the current implementation breaks some tests
Minor: New Feature? No
Tests Added + Pass? No - Added passing tests but breaking other tests
Documentation PR Link
Any Dependency Changes? No
License MIT

Since the fix is to always include parentheses for arrow functions, it breaks the following tests:

  • generation/edgecase › single arg async arrow with retainlines
  • generation/types › ArrowFunctionExpression

I'm not sure what we should do here, ideally I guess we should only wrap the param in parentheses if there's a comment proceeding the param, though I don't have any idea how to do that.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 14, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 8cae946:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@babel-bot
Copy link
Collaborator

babel-bot commented Jul 14, 2020

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

@existentialism existentialism added pkg: generator PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels Jul 14, 2020
@@ -109,7 +109,8 @@ export function ArrowFunctionExpression(node: Object) {
if (
node.params.length === 1 &&
t.isIdentifier(firstParam) &&
!hasTypes(node, firstParam)
!hasTypes(node, firstParam) &&
!node.async
) {
if (
this.format.retainLines &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can move node.async to here

this.format.retainLines || node.async

so we are instructing that if async presents, we try to retain lines and print ( if the function body is in different lines with the async arrow.

@cwohlman
Copy link
Contributor Author

Thanks @JLHwung, looks like that does the trick.

Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@JLHwung JLHwung changed the title Fix 11830 always retain lines for async arrow Jul 15, 2020
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@nicolo-ribaudo nicolo-ribaudo changed the title always retain lines for async arrow Always retain lines for async arrow Jul 15, 2020
@nicolo-ribaudo nicolo-ribaudo merged commit e12caf4 into babel:main Jul 15, 2020
@cwohlman cwohlman deleted the fix-11830 branch July 16, 2020 13:50
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 16, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 16, 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: generator PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding a comment to an async function before the first argument can result in a syntax error
5 participants