Skip to content

Commit 7dac38a

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

File tree

3 files changed

+128
-4
lines changed

3 files changed

+128
-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: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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 {
16+
// | @link IsbnSyntaxError}
17+
// | This exception is thrown if the input is not a valid ISBN number.
18+
// | ----------------------------------------------------------------------
19+
20+
[
21+
{
22+
"marker": {
23+
"fileName": "/tests/cases/fourslash/jsdocLink7.ts",
24+
"position": 194,
25+
"name": ""
26+
},
27+
"item": {
28+
"kind": "function",
29+
"kindModifiers": "",
30+
"textSpan": {
31+
"start": 179,
32+
"length": 15
33+
},
34+
"displayParts": [
35+
{
36+
"text": "function",
37+
"kind": "keyword"
38+
},
39+
{
40+
"text": " ",
41+
"kind": "space"
42+
},
43+
{
44+
"text": "fetchBookByIsbn",
45+
"kind": "functionName"
46+
},
47+
{
48+
"text": "(",
49+
"kind": "punctuation"
50+
},
51+
{
52+
"text": "isbnCode",
53+
"kind": "parameterName"
54+
},
55+
{
56+
"text": ":",
57+
"kind": "punctuation"
58+
},
59+
{
60+
"text": " ",
61+
"kind": "space"
62+
},
63+
{
64+
"text": "string",
65+
"kind": "keyword"
66+
},
67+
{
68+
"text": ")",
69+
"kind": "punctuation"
70+
},
71+
{
72+
"text": ":",
73+
"kind": "punctuation"
74+
},
75+
{
76+
"text": " ",
77+
"kind": "space"
78+
},
79+
{
80+
"text": "Book",
81+
"kind": "aliasName"
82+
}
83+
],
84+
"documentation": [],
85+
"tags": [
86+
{
87+
"name": "throws",
88+
"text": [
89+
{
90+
"text": "{",
91+
"kind": "text"
92+
}
93+
]
94+
},
95+
{
96+
"name": "link",
97+
"text": [
98+
{
99+
"text": "IsbnSyntaxError}\nThis exception is thrown if the input is not a valid ISBN number.",
100+
"kind": "text"
101+
}
102+
]
103+
}
104+
]
105+
}
106+
}
107+
]

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)