From c746477d815bb1ce3f4b7c8ea82143008ce963ce Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 29 Aug 2017 12:59:34 -0700 Subject: [PATCH] JSDoc:... binds tighter than *n* postfix jsdocs 1. Previously ...X? mistakenly parsed as ...(X?) instead of (...X)? 2. Previously X?!?!? mistakenly failed to parse the postfix tokens ? ! ? ! ? at the same level of precedence. The fix is to 1. Make ... parsing call parseNonArrayType instead of parseType. 2. Make postfix jsdoc parsing parse in a loop instead of only parsing one token. --- src/compiler/parser.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 7486c7541be..47d9afb1f70 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2178,7 +2178,7 @@ namespace ts { function parseJSDocNodeWithType(kind: SyntaxKind.JSDocVariadicType | SyntaxKind.JSDocNonNullableType): TypeNode { const result = createNode(kind) as JSDocVariadicType | JSDocNonNullableType; nextToken(); - result.type = parseType(); + result.type = parseNonArrayType(); return finishNode(result); } @@ -2740,14 +2740,15 @@ namespace ts { } function parseJSDocPostfixTypeOrHigher(): TypeNode { - const type = parseNonArrayType(); - const kind = getKind(token()); - if (!kind) return type; - nextToken(); - - const postfix = createNode(kind, type.pos) as JSDocOptionalType | JSDocNonNullableType | JSDocNullableType; - postfix.type = type; - return finishNode(postfix); + let kind: SyntaxKind | undefined; + let type = parseNonArrayType(); + while (kind = getKind(token())) { + nextToken(); + const postfix = createNode(kind, type.pos) as JSDocOptionalType | JSDocNonNullableType | JSDocNullableType; + postfix.type = type; + type = finishNode(postfix); + } + return type; function getKind(tokenKind: SyntaxKind): SyntaxKind | undefined { switch (tokenKind) {