From c5fd2f14f38d669f604f8cb40af8f3e0d747c600 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 18 Dec 2017 18:30:34 -0800 Subject: [PATCH] Parse xxx? as JSDoc type when not followed by token that starts type --- src/compiler/parser.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index debb4be67ba..9c4aba68a37 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -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);