Parse xxx? as JSDoc type when not followed by token that starts type

This commit is contained in:
Anders Hejlsberg
2017-12-18 18:30:34 -08:00
parent 100e4f6f3b
commit c5fd2f14f3

View File

@@ -1477,6 +1477,11 @@ namespace ts {
return isStartOfExpression();
}
function nextTokenIsStartOfType() {
nextToken();
return isStartOfType();
}
// True if positioned at a list terminator
function isListTerminator(kind: ParsingContext): boolean {
if (token() === SyntaxKind.EndOfFileToken) {
@@ -2767,8 +2772,8 @@ namespace ts {
type = createJSDocPostfixType(SyntaxKind.JSDocNonNullableType, type);
break;
case SyntaxKind.QuestionToken:
// only parse postfix ? inside jsdoc, otherwise it is a conditional type
if (!(contextFlags & NodeFlags.JSDoc)) {
// If not in JSDoc and next token is start of a type we have a conditional type
if (!(contextFlags & NodeFlags.JSDoc) && lookAhead(nextTokenIsStartOfType)) {
return type;
}
type = createJSDocPostfixType(SyntaxKind.JSDocNullableType, type);