Skip to content

Commit 2399bac

Browse files
author
Andy
authored
Make it a parse error for an @type jsdoc tag to not include a type (#18664)
* Make it a parse error for an `@type` jsdoc tag to not include a type * Rename parameter
1 parent 72c8b80 commit 2399bac

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/compiler/parser.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6135,10 +6135,14 @@ namespace ts {
61356135
}
61366136

61376137
// Parses out a JSDoc type expression.
6138-
export function parseJSDocTypeExpression(): JSDocTypeExpression {
6138+
export function parseJSDocTypeExpression(): JSDocTypeExpression;
6139+
export function parseJSDocTypeExpression(requireBraces: true): JSDocTypeExpression | undefined;
6140+
export function parseJSDocTypeExpression(requireBraces?: boolean): JSDocTypeExpression | undefined {
61396141
const result = <JSDocTypeExpression>createNode(SyntaxKind.JSDocTypeExpression, scanner.getTokenPos());
61406142

6141-
parseExpected(SyntaxKind.OpenBraceToken);
6143+
if (!parseExpected(SyntaxKind.OpenBraceToken) && requireBraces) {
6144+
return undefined;
6145+
}
61426146
result.type = doInsideOfContext(NodeFlags.JSDoc, parseType);
61436147
parseExpected(SyntaxKind.CloseBraceToken);
61446148

@@ -6595,7 +6599,7 @@ namespace ts {
65956599
const result = <JSDocTypeTag>createNode(SyntaxKind.JSDocTypeTag, atToken.pos);
65966600
result.atToken = atToken;
65976601
result.tagName = tagName;
6598-
result.typeExpression = tryParseTypeExpression();
6602+
result.typeExpression = parseJSDocTypeExpression(/*mayBail*/ true);
65996603
return finishNode(result);
66006604
}
66016605

src/harness/unittests/jsDocParsing.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ namespace ts {
139139
`/**
140140
* @param
141141
*/`);
142+
143+
parsesIncorrectly("noType",
144+
`/**
145+
* @type
146+
*/`);
142147
});
143148

144149
describe("parsesCorrectly", () => {
@@ -148,12 +153,6 @@ namespace ts {
148153
*/`);
149154

150155

151-
parsesCorrectly("noType",
152-
`/**
153-
* @type
154-
*/`);
155-
156-
157156
parsesCorrectly("noReturnType",
158157
`/**
159158
* @return

0 commit comments

Comments
 (0)