Skip to content

Improve @throws {@link CustomError} handling #61722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LukeAbby suggested @returns and @yields could use the same treatment. @yields isn't a specialized tag in TS today so I skipped that and I'm slightly on the fence when it comes to @returns. cc @sandersn

const typeExpression = tryParseTypeExpression();
const typeExpression = isMarkdownOrJSDocLink() ? undefined : tryParseTypeExpression();
const comment = parseTrailingTagComments(start, getNodePos(), indent, indentText);
return finishNode(factory.createJSDocThrowsTag(tagName, typeExpression, comment), start);
}
Expand Down Expand Up @@ -9881,6 +9879,10 @@ namespace Parser {
nextTokenJSDoc();
return result;
}

function isMarkdownOrJSDocLink() {
return token() === SyntaxKind.OpenBracketToken || lookAhead(() => nextTokenJSDoc() === SyntaxKind.AtToken && tokenIsIdentifierOrKeyword(nextTokenJSDoc()) && isJSDocLinkTag(scanner.getTokenValue()));
}
}
}
}
Expand Down
119 changes: 119 additions & 0 deletions tests/baselines/reference/jsdocLink7.baseline
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
}
]
15 changes: 15 additions & 0 deletions tests/cases/fourslash/jsdocLink7.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference path='fourslash.ts' />

// 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();