diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 8c69cccba1282..2c5c6af70b9de 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -9444,15 +9444,13 @@ namespace Parser { } function parseSeeTag(start: number, tagName: Identifier, indent?: number, indentText?: string): JSDocSeeTag { - const isMarkdownOrJSDocLink = token() === SyntaxKind.OpenBracketToken - || lookAhead(() => nextTokenJSDoc() === SyntaxKind.AtToken && tokenIsIdentifierOrKeyword(nextTokenJSDoc()) && isJSDocLinkTag(scanner.getTokenValue())); - const nameExpression = isMarkdownOrJSDocLink ? undefined : parseJSDocNameReference(); + const nameExpression = isMarkdownOrJSDocLink() ? undefined : parseJSDocNameReference(); const comments = indent !== undefined && indentText !== undefined ? parseTrailingTagComments(start, getNodePos(), indent, indentText) : undefined; return finishNode(factory.createJSDocSeeTag(tagName, nameExpression, comments), start); } function parseThrowsTag(start: number, tagName: Identifier, indent: number, indentText: string): JSDocThrowsTag { - const typeExpression = tryParseTypeExpression(); + const typeExpression = isMarkdownOrJSDocLink() ? undefined : tryParseTypeExpression(); const comment = parseTrailingTagComments(start, getNodePos(), indent, indentText); return finishNode(factory.createJSDocThrowsTag(tagName, typeExpression, comment), start); } @@ -9881,6 +9879,10 @@ namespace Parser { nextTokenJSDoc(); return result; } + + function isMarkdownOrJSDocLink() { + return token() === SyntaxKind.OpenBracketToken || lookAhead(() => nextTokenJSDoc() === SyntaxKind.AtToken && tokenIsIdentifierOrKeyword(nextTokenJSDoc()) && isJSDocLinkTag(scanner.getTokenValue())); + } } } } diff --git a/tests/baselines/reference/jsdocLink7.baseline b/tests/baselines/reference/jsdocLink7.baseline new file mode 100644 index 0000000000000..58e3d4e93923f --- /dev/null +++ b/tests/baselines/reference/jsdocLink7.baseline @@ -0,0 +1,119 @@ +// === QuickInfo === +=== /tests/cases/fourslash/jsdocLink7.ts === +// type Book = any; +// +// class IsbnSyntaxError extends Error {} +// +// /** +// * @throws {@link IsbnSyntaxError} +// * This exception is thrown if the input is not a valid ISBN number. +// */ +// function fetchBookByIsbn(isbnCode: string): Book {} +// ^^^^^^^^^^^^^^^ +// | ---------------------------------------------------------------------- +// | function fetchBookByIsbn(isbnCode: string): Book +// | @throws {@link IsbnSyntaxError}This exception is thrown if the input is not a valid ISBN number. +// | ---------------------------------------------------------------------- + +[ + { + "marker": { + "fileName": "/tests/cases/fourslash/jsdocLink7.ts", + "position": 194, + "name": "" + }, + "item": { + "kind": "function", + "kindModifiers": "", + "textSpan": { + "start": 179, + "length": 15 + }, + "displayParts": [ + { + "text": "function", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "fetchBookByIsbn", + "kind": "functionName" + }, + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "isbnCode", + "kind": "parameterName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "Book", + "kind": "aliasName" + } + ], + "documentation": [], + "tags": [ + { + "name": "throws", + "text": [ + { + "text": "", + "kind": "text" + }, + { + "text": "{@link ", + "kind": "link" + }, + { + "text": "IsbnSyntaxError", + "kind": "linkName", + "target": { + "fileName": "/tests/cases/fourslash/jsdocLink7.ts", + "textSpan": { + "start": 18, + "length": 38 + } + } + }, + { + "text": "}", + "kind": "link" + }, + { + "text": "This exception is thrown if the input is not a valid ISBN number.", + "kind": "text" + } + ] + } + ] + } + } +] \ No newline at end of file diff --git a/tests/cases/fourslash/jsdocLink7.ts b/tests/cases/fourslash/jsdocLink7.ts new file mode 100644 index 0000000000000..3510e97831239 --- /dev/null +++ b/tests/cases/fourslash/jsdocLink7.ts @@ -0,0 +1,15 @@ +/// + +// https://github.com/microsoft/TypeScript/issues/58599 + +//// type Book = any; +//// +//// class IsbnSyntaxError extends Error {} +//// +//// /** +//// * @throws {@link IsbnSyntaxError} +//// * This exception is thrown if the input is not a valid ISBN number. +//// */ +//// function fetchBookByIsbn/**/(isbnCode: string): Book {} + +verify.baselineQuickInfo();