-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add heuristics to detect assignments whose id has complex type annotations #10916
Conversation
src/language-js/print/assignment.js
Outdated
} | ||
} | ||
} | ||
return false; |
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.
Can we return early?
@@ -0,0 +1 @@ | |||
run_spec(__dirname, ["babel-flow"]); |
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.
Run test on flow
parser too?
src/language-js/print/assignment.js
Outdated
@@ -269,6 +273,48 @@ function isTypeAlias(node) { | |||
return node.type === "TSTypeAliasDeclaration" || node.type === "TypeAlias"; | |||
} | |||
|
|||
function isComplexTypeAnnotationForAssignments(node) { | |||
if (isAssignmentOrVariableDeclarator(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.
if (isAssignmentOrVariableDeclarator(node)) { | |
if (node.type === "VariableDeclarator") { |
src/language-js/print/assignment.js
Outdated
@@ -269,6 +273,48 @@ function isTypeAlias(node) { | |||
return node.type === "TSTypeAliasDeclaration" || node.type === "TypeAlias"; | |||
} | |||
|
|||
function isComplexTypeAnnotationForAssignments(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.
Let's rename to hasComplexTypeAnnotation
src/language-js/print/assignment.js
Outdated
@@ -139,7 +139,7 @@ function chooseLayout(path, options, print, leftDoc, rightPropertyName) { | |||
if ( | |||
isComplexDestructuring(node) || | |||
isComplexTypeAliasParams(node) || | |||
isComplexTypeAnnotationForAssignments(node) | |||
isComplexTypeAnnotation(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.
I meant has...
, not is...
. The node itself isn't a type annotation.
Description
Fixes #10850
Checklist
changelog_unreleased/*/XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨