-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Apply same single-line style to copied nodes as manufactured ones #57890
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
Apply same single-line style to copied nodes as manufactured ones #57890
Conversation
tests/baselines/reference/functionDeclarationWithArgumentOfTypeFunctionTypeArray.types
Outdated
Show resolved
Hide resolved
tests/baselines/reference/jsdocParseDotDotDotInJSDocFunction.types
Outdated
Show resolved
Hide resolved
@@ -646,7 +646,7 @@ conversionTest("testDowncast"); | |||
>"testDowncast" : "testDowncast" | |||
|
|||
function conversionTest2(groupName: | "downcast" | "dataDowncast" | "editingDowncast" | {} & `${string}Downcast`) {} | |||
>conversionTest2 : (groupName: "downcast" | "dataDowncast" | "editingDowncast" | {} & `${string}Downcast`) => void | |||
>conversionTest2 : (groupName: "downcast" | "dataDowncast" | "editingDowncast" | ({} & `${string}Downcast`)) => void |
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.
Just commenting on the ones that aren't whitespace only for visiblity
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 think this is because our parenthesizer when we clone the node is stricter than the syntax allows. I'll have to check.
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.
Yeah, now that we make a new node to apply SingleLine
to the {}
, the node goes through the parenthesizer, and the relevant rule is
// UnionType[Extends] :
// `|`? IntersectionType[?Extends]
// UnionType[?Extends] `|` IntersectionType[?Extends]
//
// - A union type constituent has the same precedence as the check type of a conditional type
function parenthesizeConstituentTypeOfUnionType(type: TypeNode) {
switch (type.kind) {
case SyntaxKind.UnionType: // Not strictly necessary, but a union containing a union should have been flattened
case SyntaxKind.IntersectionType: // Not strictly necessary, but makes generated output more readable and avoids breaks in DT tests
return factory.createParenthesizedType(type);
}
return parenthesizeCheckTypeOfConditionalType(type);
}
which acknowledges it's extraneous.
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 do wonder if there's a still a reason to do it; the union case seems like overkill, and I recently changed ExpectType to normalize unions and could probably just make it always strip or add the parens.
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 sent #57900 which shows the affect of this; I do sorta think we should stop doing this as I don't think that the extra parens are that much of an improvement?
But, on its own I think this particular change is alright.
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.
Personally I found it a bit easier to read with the parens, so consider that a soft vote for keeping the parens.
I do wonder if there's a still a reason to do it; the union case seems like overkill
Are there cases of non-normalization to consider?
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.
These are purely syntactic things we modify when synthetically creating nodes, so, no.
I feel like I want this, but the fact that we don't do this at the moment means that we can actually see node reuse changes in other PRs, so I'm sorta thinking that it'd be nice to see what a future reuse indicator might be... But I'm not sure what that will be yet. |
The whitespace only worked as an indicator object literal types - if we want a similar restriction, we can instrument the printer to print |
@jakebailey I have a draft of a followup PR that explicitly underlines type nodes without positional mappings in the
that should do much nicer to actually track the desired information, without being too overbearing. The extra linebreaks, IMO, also make the type baselines a smidge more readable. |
+600k line diff, though 😄 |
I brought this up before, but not applying these emit styles to copied nodes in the node builder makes reusing more input nodes a fairly noisy activity in the test baselines (which might itself be a good thing, but not intentional), and, moreover, makes the types print poorly in error messages (with lots of tabs -
.types
baselines use basically the same print settings errors do). I'd like to take this chance to correct that and apply the node builder's "house style" to any nodes we copy (which is to say:SingleLine
everything - except object literal types when the node builder flag to print them multiline is set).