Skip to content

Commit c746477

Browse files
committed
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.
1 parent 450c32a commit c746477

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/compiler/parser.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,7 @@ namespace ts {
21782178
function parseJSDocNodeWithType(kind: SyntaxKind.JSDocVariadicType | SyntaxKind.JSDocNonNullableType): TypeNode {
21792179
const result = createNode(kind) as JSDocVariadicType | JSDocNonNullableType;
21802180
nextToken();
2181-
result.type = parseType();
2181+
result.type = parseNonArrayType();
21822182
return finishNode(result);
21832183
}
21842184

@@ -2740,14 +2740,15 @@ namespace ts {
27402740
}
27412741

27422742
function parseJSDocPostfixTypeOrHigher(): TypeNode {
2743-
const type = parseNonArrayType();
2744-
const kind = getKind(token());
2745-
if (!kind) return type;
2746-
nextToken();
2747-
2748-
const postfix = createNode(kind, type.pos) as JSDocOptionalType | JSDocNonNullableType | JSDocNullableType;
2749-
postfix.type = type;
2750-
return finishNode(postfix);
2743+
let kind: SyntaxKind | undefined;
2744+
let type = parseNonArrayType();
2745+
while (kind = getKind(token())) {
2746+
nextToken();
2747+
const postfix = createNode(kind, type.pos) as JSDocOptionalType | JSDocNonNullableType | JSDocNullableType;
2748+
postfix.type = type;
2749+
type = finishNode(postfix);
2750+
}
2751+
return type;
27512752

27522753
function getKind(tokenKind: SyntaxKind): SyntaxKind | undefined {
27532754
switch (tokenKind) {

0 commit comments

Comments
 (0)