-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Preserve string delimiter in type printing. #60729
base: main
Are you sure you want to change the base?
Preserve string delimiter in type printing. #60729
Conversation
We looked at this in the design meeting; the general consensus is that this is good for declaration files, but the fact that error messages are changing quote styles seems to be wrong; we should try and make diagnostic type printing normalize to |
Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page. Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up. |
@@ -8,7 +8,7 @@ declare namespace demoNS { | |||
>f : Symbol(f, Decl(demo.d.ts, 0, 26)) | |||
} | |||
declare module 'demoModule' { | |||
>'demoModule' : Symbol("demoModule", Decl(demo.d.ts, 2, 1)) | |||
>'demoModule' : Symbol('demoModule', Decl(demo.d.ts, 2, 1)) |
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'm surprised to see symbol baselines change; were we inconsistent with these before?
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.
Symbol printing is involved in type printing and error printing. I applied the 'preserve source code delimiters in everything except errors' to the symbol printing too. This does mean that the delimiters are now preserved in symbol baselines where they previously were not.
Were they always replaced before? Don't think so. Some error messages used symbol printing for the property names and we can see in error baselines changes that some of those kept the '
delimiter instead of having it replaced with "
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.
Hm, I tried doing this in typeWriter.ts
:
let symbolString = "Symbol(" + this.checker.symbolToString(symbol, node.parent, undefined, ts.SymbolFormatFlags.AllowAnyNodeKind | ts.SymbolFormatFlags.UseDoubleQuotesForStringLiteralType);
And it actually still changed a whole bunch of double quotes to single quotes.... Is there some place which is not respecting the flag?
tests/baselines/reference/assignmentCompatWithObjectMembersStringNumericNames.errors.txt
Show resolved
Hide resolved
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 read through all of the baselines; mostly seems correct, with some odd escaping changes, and I would like someone familiar with those displayParts to weigh in on those changes.
tests/baselines/reference/objectLiteralGettersAndSetters.symbols
Outdated
Show resolved
Hide resolved
tests/baselines/reference/objectTypeWithStringNamedPropertyOfIllegalCharacters.symbols
Outdated
Show resolved
Hide resolved
tests/baselines/reference/stringLiteralPropertyNameWithLineContinuation1.symbols
Outdated
Show resolved
Hide resolved
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
@@ -8,7 +8,7 @@ declare namespace demoNS { | |||
>f : Symbol(f, Decl(demo.d.ts, 0, 26)) | |||
} | |||
declare module 'demoModule' { | |||
>'demoModule' : Symbol("demoModule", Decl(demo.d.ts, 2, 1)) | |||
>'demoModule' : Symbol('demoModule', Decl(demo.d.ts, 2, 1)) |
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.
Hm, I tried doing this in typeWriter.ts
:
let symbolString = "Symbol(" + this.checker.symbolToString(symbol, node.parent, undefined, ts.SymbolFormatFlags.AllowAnyNodeKind | ts.SymbolFormatFlags.UseDoubleQuotesForStringLiteralType);
And it actually still changed a whole bunch of double quotes to single quotes.... Is there some place which is not respecting the flag?
The PR seems good to me, outside my comment above about symbol baselines and the weird quoting not changing where I expected it to. |
I did not see places where the delimiter was replaced, I did see places where the delimiters were preserved as in source code. This is because there are still cases where an identifier is created from whatever text was in the computed property. // in symbolToExpression
if (canUsePropertyAccess(symbolName, languageVersion) || (index === 0 && firstChar === CharacterCodes.openBracket)) {
const identifier = setEmitFlags(factory.createIdentifier(symbolName), EmitFlags.NoAsciiEscaping);
if (typeParameterNodes) setIdentifierTypeArguments(identifier, factory.createNodeArray<TypeNode | TypeParameterDeclaration>(typeParameterNodes));
identifier.symbol = symbol;
return index > 0 ? factory.createPropertyAccessExpression(createExpressionFromSymbolChain(chain, index - 1), identifier) : identifier;
} Because I am working on changing this, but it's proving a bit trickier than I expected. Will push tomorrow a version that does not just reuse text if |
Related to #60540
This PR shows what the impact of preserving string delimiters in type printing would be.
cc: @jakebailey @weswigham