-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Avoid to break after assignment for call expression that has complex type parameters #10949
Conversation
src/language-js/print/assignment.js
Outdated
const hasComplexTypeParams = | ||
node.typeParameters && | ||
isNonEmptyArray(node.typeParameters.params) && | ||
willBreak(print("typeParameters")); |
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.
Please add one more condition: if there is more than one type argument, the call shouldn't be considered "poorly breakable".
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.
And another case: the only type argument is a union type.
src/language-js/print/assignment.js
Outdated
function isCallExpressionWithComplexTypeParameters(node, print) { | ||
if ( | ||
isCallExpression(node) && | ||
node.typeParameters && |
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.
In Flow AST, it's typeArguments
instead of typeParameters
src/language-js/print/assignment.js
Outdated
return false; | ||
} | ||
|
||
function getTypeParametersFromCallExpression(node) { |
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.
function getTypeParametersFromCallExpression(node) { | |
function getCallExpressionTypeArguments(node) { |
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.
'arguments' in this case is a more correct word
src/language-js/print/assignment.js
Outdated
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
function getTypeParametersFromCallExpression(node) { | ||
function getTypeArgumentsFromCallExpression(node) { | ||
if (isCallExpression(node)) { |
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.
As long as this function isn't used anywhere else this check is redundant.
Description
(I made a mistake in the branch name)
Fixes #10846
Checklist
changelog_unreleased/*/XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨