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

Avoid to break after assignment for call expression that has complex type parameters #10949

Merged
merged 9 commits into from
May 28, 2021

Conversation

sosukesuzuki
Copy link
Member

Description

(I made a mistake in the branch name)

Fixes #10846

Checklist

  • I’ve added tests to confirm my change works.
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

const hasComplexTypeParams =
node.typeParameters &&
isNonEmptyArray(node.typeParameters.params) &&
willBreak(print("typeParameters"));
Copy link
Member

@thorn0 thorn0 May 25, 2021

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".

Copy link
Member

@thorn0 thorn0 May 25, 2021

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.

function isCallExpressionWithComplexTypeParameters(node, print) {
if (
isCallExpression(node) &&
node.typeParameters &&
Copy link
Member

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

return false;
}

function getTypeParametersFromCallExpression(node) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function getTypeParametersFromCallExpression(node) {
function getCallExpressionTypeArguments(node) {

Copy link
Member

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

return true;
}
}
return false;
}

function getTypeParametersFromCallExpression(node) {
function getTypeArgumentsFromCallExpression(node) {
if (isCallExpression(node)) {
Copy link
Member

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.

@sosukesuzuki sosukesuzuki merged commit 84f72be into prettier:main May 28, 2021
@sosukesuzuki sosukesuzuki deleted the fix-10737 branch May 28, 2021 01:40
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Weird behaviour depending on number of arguments of generic function call for new assignment formatting in 2.3
2 participants