-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Disambiguate string literal types from other string literals. #5725
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,6 +205,7 @@ namespace ts { | |
IntersectionType, | ||
ParenthesizedType, | ||
ThisType, | ||
StringLiteralType, | ||
// Binding patterns | ||
ObjectBindingPattern, | ||
ArrayBindingPattern, | ||
|
@@ -350,7 +351,7 @@ namespace ts { | |
FirstFutureReservedWord = ImplementsKeyword, | ||
LastFutureReservedWord = YieldKeyword, | ||
FirstTypeNode = TypePredicate, | ||
LastTypeNode = ThisType, | ||
LastTypeNode = StringLiteralType, | ||
FirstPunctuation = OpenBraceToken, | ||
LastPunctuation = CaretEqualsToken, | ||
FirstToken = Unknown, | ||
|
@@ -790,10 +791,13 @@ namespace ts { | |
type: TypeNode; | ||
} | ||
|
||
// Note that a StringLiteral AST node is both an Expression and a TypeNode. The latter is | ||
// because string literals can appear in type annotations as well. | ||
// @kind(SyntaxKind.StringLiteralType) | ||
export interface StringLiteralTypeNode extends LiteralLikeNode, TypeNode { | ||
_stringLiteralTypeBrand: any; | ||
} | ||
|
||
// @kind(SyntaxKind.StringLiteral) | ||
export interface StringLiteral extends LiteralExpression, TypeNode { | ||
export interface StringLiteral extends LiteralExpression { | ||
_stringLiteralBrand: any; | ||
} | ||
|
||
|
@@ -911,24 +915,32 @@ namespace ts { | |
body: ConciseBody; | ||
} | ||
|
||
export interface LiteralLikeNode extends Node { | ||
text: string; | ||
isUnterminated?: boolean; | ||
hasExtendedUnicodeEscape?: boolean; | ||
} | ||
|
||
// The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral, | ||
// or any literal of a template, this means quotes have been removed and escapes have been converted to actual characters. | ||
// For a NumericLiteral, the stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1". | ||
// @kind(SyntaxKind.NumericLiteral) | ||
// @kind(SyntaxKind.RegularExpressionLiteral) | ||
// @kind(SyntaxKind.NoSubstitutionTemplateLiteral) | ||
export interface LiteralExpression extends LiteralLikeNode, PrimaryExpression { | ||
_literalExpressionBrand: any; | ||
} | ||
|
||
// @kind(SyntaxKind.TemplateHead) | ||
// @kind(SyntaxKind.TemplateMiddle) | ||
// @kind(SyntaxKind.TemplateTail) | ||
export interface LiteralExpression extends PrimaryExpression { | ||
text: string; | ||
isUnterminated?: boolean; | ||
hasExtendedUnicodeEscape?: boolean; | ||
export interface TemplateLiteralFragment extends LiteralLikeNode { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
_templateLiteralFragmentBrand: any; | ||
} | ||
|
||
// @kind(SyntaxKind.TemplateExpression) | ||
export interface TemplateExpression extends PrimaryExpression { | ||
head: LiteralExpression; | ||
head: TemplateLiteralFragment; | ||
templateSpans: NodeArray<TemplateSpan>; | ||
} | ||
|
||
|
@@ -937,7 +949,7 @@ namespace ts { | |
// @kind(SyntaxKind.TemplateSpan) | ||
export interface TemplateSpan extends Node { | ||
expression: Expression; | ||
literal: LiteralExpression; | ||
literal: TemplateLiteralFragment; | ||
} | ||
|
||
// @kind(SyntaxKind.ParenthesizedExpression) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 you add a
// TODO (drosen): Use this function in 'checkStringLiteralExpression'.
?I need to see how this affects things, but I don't want it to affect your work.
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'll put a comment in checkStringLiteralExpression instead. The big difference is that getTypeFromStringLiteral caches the type on the resolvedType of the node's NodeLinks.