JSDoc understands string literal types

Unfortunately, I didn't find a way to reuse the normal string literal
type, so I had to extend the existing JSDoc type hierarchy. Otherwise,
this feature is very simple.
This commit is contained in:
Nathan Shively-Sanders
2016-07-27 13:21:42 -07:00
parent c578367c26
commit a6642d68c9
7 changed files with 69 additions and 1 deletions

View File

@@ -5326,6 +5326,8 @@ namespace ts {
return getTypeFromThisTypeNode(node);
case SyntaxKind.StringLiteralType:
return getTypeFromStringLiteralTypeNode(<StringLiteralTypeNode>node);
case SyntaxKind.JSDocStringLiteralType:
return getTypeFromStringLiteralTypeNode((<JSDocStringLiteralType>node).stringLiteral);
case SyntaxKind.TypeReference:
case SyntaxKind.JSDocTypeReference:
return getTypeFromTypeReference(<TypeReferenceNode>node);

View File

@@ -5860,9 +5860,10 @@ namespace ts {
case SyntaxKind.SymbolKeyword:
case SyntaxKind.VoidKeyword:
return parseTokenNode<JSDocType>();
case SyntaxKind.StringLiteral:
return parseJSDocStringLiteralType();
}
// TODO (drosen): Parse string literal types in JSDoc as well.
return parseJSDocTypeReference();
}
@@ -6041,6 +6042,12 @@ namespace ts {
return finishNode(result);
}
function parseJSDocStringLiteralType(): JSDocStringLiteralType {
const result = <JSDocStringLiteralType>createNode(SyntaxKind.JSDocStringLiteralType);
result.stringLiteral = parseStringLiteralTypeNode();
return finishNode(result);
}
function parseJSDocUnknownOrNullableType(): JSDocUnknownType | JSDocNullableType {
const pos = scanner.getStartPos();
// skip the ?

View File

@@ -346,6 +346,7 @@ namespace ts {
JSDocTypedefTag,
JSDocPropertyTag,
JSDocTypeLiteral,
JSDocStringLiteralType,
// Synthesized list
SyntaxList,
@@ -1491,6 +1492,10 @@ namespace ts {
type: JSDocType;
}
export interface JSDocStringLiteralType extends JSDocType {
stringLiteral: StringLiteralTypeNode;
}
export type JSDocTypeReferencingNode = JSDocThisType | JSDocConstructorType | JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType;
// @kind(SyntaxKind.JSDocRecordMember)