Skip to content

Commit 7c10135

Browse files
authored
Don't start jsdoc tag before whitespace (#43602)
Fixes #43580
1 parent 0487b38 commit 7c10135

File tree

3 files changed

+212
-2
lines changed

3 files changed

+212
-2
lines changed

src/compiler/parser.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7655,8 +7655,9 @@ namespace ts {
76557655
indent = 0;
76567656
break;
76577657
case SyntaxKind.AtToken:
7658-
if (state === JSDocState.SavingBackticks || !previousWhitespace && state === JSDocState.SavingComments) {
7659-
// @ doesn't start a new tag inside ``, and inside a comment, only after whitespace
7658+
if (state === JSDocState.SavingBackticks
7659+
|| state === JSDocState.SavingComments && (!previousWhitespace || lookAhead(isNextJSDocTokenWhitespace))) {
7660+
// @ doesn't start a new tag inside ``, and inside a comment, only after whitespace or not before whitespace
76607661
comments.push(scanner.getTokenText());
76617662
break;
76627663
}
@@ -7735,6 +7736,11 @@ namespace ts {
77357736
}
77367737
}
77377738

7739+
function isNextJSDocTokenWhitespace() {
7740+
const next = nextTokenJSDoc();
7741+
return next === SyntaxKind.WhitespaceTrivia || next === SyntaxKind.NewLineTrivia;
7742+
}
7743+
77387744
function parseJSDocLink(start: number) {
77397745
if (!tryParse(parseJSDocLinkPrefix)) {
77407746
return undefined;
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
[
2+
{
3+
"marker": {
4+
"fileName": "/tests/cases/fourslash/quickInfoJSDocAtBeforeSpace.ts",
5+
"position": 39,
6+
"name": "f"
7+
},
8+
"quickInfo": {
9+
"kind": "function",
10+
"kindModifiers": "",
11+
"textSpan": {
12+
"start": 39,
13+
"length": 1
14+
},
15+
"displayParts": [
16+
{
17+
"text": "function",
18+
"kind": "keyword"
19+
},
20+
{
21+
"text": " ",
22+
"kind": "space"
23+
},
24+
{
25+
"text": "f",
26+
"kind": "functionName"
27+
},
28+
{
29+
"text": "(",
30+
"kind": "punctuation"
31+
},
32+
{
33+
"text": ")",
34+
"kind": "punctuation"
35+
},
36+
{
37+
"text": ":",
38+
"kind": "punctuation"
39+
},
40+
{
41+
"text": " ",
42+
"kind": "space"
43+
},
44+
{
45+
"text": "void",
46+
"kind": "keyword"
47+
}
48+
],
49+
"documentation": [],
50+
"tags": [
51+
{
52+
"name": "return",
53+
"text": [
54+
{
55+
"text": "Don't @ me",
56+
"kind": "text"
57+
}
58+
]
59+
}
60+
]
61+
}
62+
},
63+
{
64+
"marker": {
65+
"fileName": "/tests/cases/fourslash/quickInfoJSDocAtBeforeSpace.ts",
66+
"position": 87,
67+
"name": "g"
68+
},
69+
"quickInfo": {
70+
"kind": "function",
71+
"kindModifiers": "",
72+
"textSpan": {
73+
"start": 87,
74+
"length": 1
75+
},
76+
"displayParts": [
77+
{
78+
"text": "function",
79+
"kind": "keyword"
80+
},
81+
{
82+
"text": " ",
83+
"kind": "space"
84+
},
85+
{
86+
"text": "g",
87+
"kind": "functionName"
88+
},
89+
{
90+
"text": "(",
91+
"kind": "punctuation"
92+
},
93+
{
94+
"text": ")",
95+
"kind": "punctuation"
96+
},
97+
{
98+
"text": ":",
99+
"kind": "punctuation"
100+
},
101+
{
102+
"text": " ",
103+
"kind": "space"
104+
},
105+
{
106+
"text": "void",
107+
"kind": "keyword"
108+
}
109+
],
110+
"documentation": [],
111+
"tags": [
112+
{
113+
"name": "return",
114+
"text": [
115+
{
116+
"text": "One final @",
117+
"kind": "text"
118+
}
119+
]
120+
}
121+
]
122+
}
123+
},
124+
{
125+
"marker": {
126+
"fileName": "/tests/cases/fourslash/quickInfoJSDocAtBeforeSpace.ts",
127+
"position": 148,
128+
"name": "h"
129+
},
130+
"quickInfo": {
131+
"kind": "function",
132+
"kindModifiers": "",
133+
"textSpan": {
134+
"start": 148,
135+
"length": 1
136+
},
137+
"displayParts": [
138+
{
139+
"text": "function",
140+
"kind": "keyword"
141+
},
142+
{
143+
"text": " ",
144+
"kind": "space"
145+
},
146+
{
147+
"text": "h",
148+
"kind": "functionName"
149+
},
150+
{
151+
"text": "(",
152+
"kind": "punctuation"
153+
},
154+
{
155+
"text": ")",
156+
"kind": "punctuation"
157+
},
158+
{
159+
"text": ":",
160+
"kind": "punctuation"
161+
},
162+
{
163+
"text": " ",
164+
"kind": "space"
165+
},
166+
{
167+
"text": "void",
168+
"kind": "keyword"
169+
}
170+
],
171+
"documentation": [],
172+
"tags": [
173+
{
174+
"name": "return",
175+
"text": [
176+
{
177+
"text": "An @\nBut another line",
178+
"kind": "text"
179+
}
180+
]
181+
}
182+
]
183+
}
184+
}
185+
]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
//// /**
4+
//// * @return Don't @ me
5+
//// */
6+
//// function /*f*/f() { }
7+
//// /**
8+
//// * @return One final @
9+
//// */
10+
//// function /*g*/g() { }
11+
//// /**
12+
//// * @return An @
13+
//// * But another line
14+
//// */
15+
//// function /*h*/h() { }
16+
17+
18+
verify.baselineQuickInfo()
19+

0 commit comments

Comments
 (0)