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

Always retain lines for async arrow #11836

merged 6 commits into from Jul 15, 2020

Conversation

@cwohlman
Copy link
Contributor

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
Copy link

codesandbox 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/

@@ -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 &&

This comment has been minimized.

@JLHwung

JLHwung Jul 15, 2020 Contributor

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 added 2 commits Jul 15, 2020
@cwohlman
Copy link
Contributor Author

cwohlman commented Jul 15, 2020

Thanks @JLHwung, looks like that does the trick.

Copy link
Contributor

JLHwung left a comment

Thanks.

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

nicolo-ribaudo left a comment

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
8 of 9 checks passed
8 of 9 checks passed
build
Details
test262-pr Workflow: test262-pr
Details
Gitpod Open an online workspace in Gitpod
Details
Travis CI - Pull Request Build Passed
Details
babel/repl REPL preview is available
Details
build-standalone Workflow: build-standalone
Details
ci/codesandbox Building packages succeeded.
Details
codecov/project 91.85% (target 90.00%)
Details
e2e Workflow: e2e
Details
@cwohlman cwohlman deleted the xolvio:fix-11830 branch Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants
You can’t perform that action at this time.