Repository navigation
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:
|
|
|
||
| const { | ||
| [(_ref) => { | ||
| [_ref => { |
There was a problem hiding this comment.
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.
This doesn't type-check because predicate isn't declared on ArrowFunctionExpression.
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.