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
Conversation
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:
|
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 && |
There was a problem hiding this comment.
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.
Thanks @JLHwung, looks like that does the trick. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
First stab at fixing #11830, fixes the bug but has other issues.
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.