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
Simplify the special-case printing of single-param arrow functions #13204
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/45569/ |
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 c2716a7:
|
@@ -1,7 +1,7 @@ | |||
var _ref2; | |||
|
|||
const { | |||
[(_ref) => { | |||
[_ref => { |
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.
I looked into why some of these arrow functions are losing their parens.
It turns out that the previous implementation of hasTypes
was checking param.trailingComments
, which is truthy when trailingComments
is an empty array.
Switching to param.trailingComments?.length
makes the generator conclude that this arrow function doesn't need parentheses after all.
// @ts-expect-error | ||
node.predicate || |
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.
This doesn't type-check because predicate
isn't declared on ArrowFunctionExpression
.
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!
This is an alternate version of #13202 that retains the special-case handling for single-parameter arrow functions, and instead tries to make it simpler and more robust.
We still remove the complex special-case code for printing single-parameter arrow functions with parentheses, and just delegate to the regular parameter-printing code in that case.