Skip to content

Commit 5d7ead4

Browse files
committed
Improve @throws {@link CustomError} handling
1 parent 81c9518 commit 5d7ead4

File tree

3 files changed

+140
-4
lines changed

3 files changed

+140
-4
lines changed

src/compiler/parser.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9444,15 +9444,13 @@ namespace Parser {
94449444
}
94459445

94469446
function parseSeeTag(start: number, tagName: Identifier, indent?: number, indentText?: string): JSDocSeeTag {
9447-
const isMarkdownOrJSDocLink = token() === SyntaxKind.OpenBracketToken
9448-
|| lookAhead(() => nextTokenJSDoc() === SyntaxKind.AtToken && tokenIsIdentifierOrKeyword(nextTokenJSDoc()) && isJSDocLinkTag(scanner.getTokenValue()));
9449-
const nameExpression = isMarkdownOrJSDocLink ? undefined : parseJSDocNameReference();
9447+
const nameExpression = isMarkdownOrJSDocLink() ? undefined : parseJSDocNameReference();
94509448
const comments = indent !== undefined && indentText !== undefined ? parseTrailingTagComments(start, getNodePos(), indent, indentText) : undefined;
94519449
return finishNode(factory.createJSDocSeeTag(tagName, nameExpression, comments), start);
94529450
}
94539451

94549452
function parseThrowsTag(start: number, tagName: Identifier, indent: number, indentText: string): JSDocThrowsTag {
9455-
const typeExpression = tryParseTypeExpression();
9453+
const typeExpression = isMarkdownOrJSDocLink() ? undefined : tryParseTypeExpression();
94569454
const comment = parseTrailingTagComments(start, getNodePos(), indent, indentText);
94579455
return finishNode(factory.createJSDocThrowsTag(tagName, typeExpression, comment), start);
94589456
}
@@ -9881,6 +9879,10 @@ namespace Parser {
98819879
nextTokenJSDoc();
98829880
return result;
98839881
}
9882+
9883+
function isMarkdownOrJSDocLink() {
9884+
return token() === SyntaxKind.OpenBracketToken || lookAhead(() => nextTokenJSDoc() === SyntaxKind.AtToken && tokenIsIdentifierOrKeyword(nextTokenJSDoc()) && isJSDocLinkTag(scanner.getTokenValue()));
9885+
}
98849886
}
98859887
}
98869888
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// === QuickInfo ===
2+
=== /tests/cases/fourslash/jsdocLink7.ts ===
3+
// type Book = any;
4+
//
5+
// class IsbnSyntaxError extends Error {}
6+
//
7+
// /**
8+
// * @throws {@link IsbnSyntaxError}
9+
// * This exception is thrown if the input is not a valid ISBN number.
10+
// */
11+
// function fetchBookByIsbn(isbnCode: string): Book {}
12+
// ^^^^^^^^^^^^^^^
13+
// | ----------------------------------------------------------------------
14+
// | function fetchBookByIsbn(isbnCode: string): Book
15+
// | @throws {@link IsbnSyntaxError}This exception is thrown if the input is not a valid ISBN number.
16+
// | ----------------------------------------------------------------------
17+
18+
[
19+
{
20+
"marker": {
21+
"fileName": "/tests/cases/fourslash/jsdocLink7.ts",
22+
"position": 194,
23+
"name": ""
24+
},
25+
"item": {
26+
"kind": "function",
27+
"kindModifiers": "",
28+
"textSpan": {
29+
"start": 179,
30+
"length": 15
31+
},
32+
"displayParts": [
33+
{
34+
"text": "function",
35+
"kind": "keyword"
36+
},
37+
{
38+
"text": " ",
39+
"kind": "space"
40+
},
41+
{
42+
"text": "fetchBookByIsbn",
43+
"kind": "functionName"
44+
},
45+
{
46+
"text": "(",
47+
"kind": "punctuation"
48+
},
49+
{
50+
"text": "isbnCode",
51+
"kind": "parameterName"
52+
},
53+
{
54+
"text": ":",
55+
"kind": "punctuation"
56+
},
57+
{
58+
"text": " ",
59+
"kind": "space"
60+
},
61+
{
62+
"text": "string",
63+
"kind": "keyword"
64+
},
65+
{
66+
"text": ")",
67+
"kind": "punctuation"
68+
},
69+
{
70+
"text": ":",
71+
"kind": "punctuation"
72+
},
73+
{
74+
"text": " ",
75+
"kind": "space"
76+
},
77+
{
78+
"text": "Book",
79+
"kind": "aliasName"
80+
}
81+
],
82+
"documentation": [],
83+
"tags": [
84+
{
85+
"name": "throws",
86+
"text": [
87+
{
88+
"text": "",
89+
"kind": "text"
90+
},
91+
{
92+
"text": "{@link ",
93+
"kind": "link"
94+
},
95+
{
96+
"text": "IsbnSyntaxError",
97+
"kind": "linkName",
98+
"target": {
99+
"fileName": "/tests/cases/fourslash/jsdocLink7.ts",
100+
"textSpan": {
101+
"start": 18,
102+
"length": 38
103+
}
104+
}
105+
},
106+
{
107+
"text": "}",
108+
"kind": "link"
109+
},
110+
{
111+
"text": "This exception is thrown if the input is not a valid ISBN number.",
112+
"kind": "text"
113+
}
114+
]
115+
}
116+
]
117+
}
118+
}
119+
]

tests/cases/fourslash/jsdocLink7.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// https://github.com/microsoft/TypeScript/issues/58599
4+
5+
//// type Book = any;
6+
////
7+
//// class IsbnSyntaxError extends Error {}
8+
////
9+
//// /**
10+
//// * @throws {@link IsbnSyntaxError}
11+
//// * This exception is thrown if the input is not a valid ISBN number.
12+
//// */
13+
//// function fetchBookByIsbn/**/(isbnCode: string): Book {}
14+
15+
verify.baselineQuickInfo();

0 commit comments

Comments
 (0)