Skip to content

Commit 688215a

Browse files
committed
fix(47391): omit | token from jsdoc linkTag text
1 parent 0019c01 commit 688215a

File tree

8 files changed

+174
-5
lines changed

8 files changed

+174
-5
lines changed

src/services/utilities.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,13 +2307,18 @@ namespace ts {
23072307
: "linkplain";
23082308
const parts = [linkPart(`{@${prefix} `)];
23092309
if (!link.name) {
2310-
if (link.text) parts.push(linkTextPart(link.text));
2310+
if (link.text) {
2311+
const text = skipSeparatorFromLinkText(link.text);
2312+
if (text) {
2313+
parts.push(linkTextPart(text));
2314+
}
2315+
}
23112316
}
23122317
else {
23132318
const symbol = checker?.getSymbolAtLocation(link.name);
23142319
const suffix = findLinkNameEnd(link.text);
23152320
const name = getTextOfNode(link.name) + link.text.slice(0, suffix);
2316-
const text = link.text.slice(suffix);
2321+
const text = skipSeparatorFromLinkText(link.text.slice(suffix));
23172322
const decl = symbol?.valueDeclaration || symbol?.declarations?.[0];
23182323
if (decl) {
23192324
parts.push(linkNamePart(name, decl));
@@ -2327,6 +2332,15 @@ namespace ts {
23272332
return parts;
23282333
}
23292334

2335+
function skipSeparatorFromLinkText(text: string) {
2336+
let pos = 0;
2337+
if (text.charCodeAt(pos++) === CharacterCodes.bar) {
2338+
while (pos < text.length && text.charCodeAt(pos) === CharacterCodes.space) pos++;
2339+
return text.slice(pos);
2340+
}
2341+
return text;
2342+
}
2343+
23302344
function findLinkNameEnd(text: string) {
23312345
if (text.indexOf("()") === 0) return 2;
23322346
if (text[0] !== "<") return 0;

tests/baselines/reference/jsdocLink1.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
}
142142
},
143143
{
144-
"text": "|postfix text",
144+
"text": "postfix text",
145145
"kind": "linkText"
146146
},
147147
{

tests/baselines/reference/jsdocLink2.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
}
142142
},
143143
{
144-
"text": "|postfix text",
144+
"text": "postfix text",
145145
"kind": "linkText"
146146
},
147147
{

tests/baselines/reference/jsdocLink3.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
}
142142
},
143143
{
144-
"text": "|postfix text",
144+
"text": "postfix text",
145145
"kind": "linkText"
146146
},
147147
{
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
[
2+
{
3+
"marker": {
4+
"fileName": "/tests/cases/fourslash/quickInfoLink4.ts",
5+
"position": 67,
6+
"name": ""
7+
},
8+
"quickInfo": {
9+
"kind": "const",
10+
"kindModifiers": "",
11+
"textSpan": {
12+
"start": 67,
13+
"length": 1
14+
},
15+
"displayParts": [
16+
{
17+
"text": "const",
18+
"kind": "keyword"
19+
},
20+
{
21+
"text": " ",
22+
"kind": "space"
23+
},
24+
{
25+
"text": "B",
26+
"kind": "localName"
27+
},
28+
{
29+
"text": ":",
30+
"kind": "punctuation"
31+
},
32+
{
33+
"text": " ",
34+
"kind": "space"
35+
},
36+
{
37+
"text": "456",
38+
"kind": "stringLiteral"
39+
}
40+
],
41+
"documentation": [
42+
{
43+
"text": "See ",
44+
"kind": "text"
45+
},
46+
{
47+
"text": "{@link ",
48+
"kind": "link"
49+
},
50+
{
51+
"text": "A",
52+
"kind": "linkName",
53+
"target": {
54+
"fileName": "/tests/cases/fourslash/quickInfoLink4.ts",
55+
"textSpan": {
56+
"start": 6,
57+
"length": 7
58+
}
59+
}
60+
},
61+
{
62+
"text": "constant A",
63+
"kind": "linkText"
64+
},
65+
{
66+
"text": "}",
67+
"kind": "link"
68+
},
69+
{
70+
"text": " instead",
71+
"kind": "text"
72+
}
73+
]
74+
}
75+
}
76+
]
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
[
2+
{
3+
"marker": {
4+
"fileName": "/tests/cases/fourslash/quickInfoLink5.ts",
5+
"position": 61,
6+
"name": ""
7+
},
8+
"quickInfo": {
9+
"kind": "const",
10+
"kindModifiers": "",
11+
"textSpan": {
12+
"start": 61,
13+
"length": 1
14+
},
15+
"displayParts": [
16+
{
17+
"text": "const",
18+
"kind": "keyword"
19+
},
20+
{
21+
"text": " ",
22+
"kind": "space"
23+
},
24+
{
25+
"text": "B",
26+
"kind": "localName"
27+
},
28+
{
29+
"text": ":",
30+
"kind": "punctuation"
31+
},
32+
{
33+
"text": " ",
34+
"kind": "space"
35+
},
36+
{
37+
"text": "456",
38+
"kind": "stringLiteral"
39+
}
40+
],
41+
"documentation": [
42+
{
43+
"text": "See ",
44+
"kind": "text"
45+
},
46+
{
47+
"text": "{@link ",
48+
"kind": "link"
49+
},
50+
{
51+
"text": "}",
52+
"kind": "link"
53+
},
54+
{
55+
"text": " instead",
56+
"kind": "text"
57+
}
58+
]
59+
}
60+
}
61+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////const A = 123;
4+
/////**
5+
//// * See {@link A | constant A} instead
6+
//// */
7+
////const /**/B = 456;
8+
9+
verify.baselineQuickInfo();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////const A = 123;
4+
/////**
5+
//// * See {@link | } instead
6+
//// */
7+
////const /**/B = 456;
8+
9+
verify.baselineQuickInfo();

0 commit comments

Comments
 (0)