Skip to content

Commit d28072d

Browse files
committed
fix: @param / @returns overly sensitive to whitespace
Closes #1164
1 parent 6a762f0 commit d28072d

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

src/lib/converter/factories/comment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export function parseComment(text: string, comment: Comment = new Comment()): Co
167167
function readTagLine(line: string, tag: RegExpExecArray) {
168168
let tagName = tag[1].toLowerCase();
169169
let paramName: string | undefined;
170-
line = line.substr(tagName.length + 1).trim();
170+
line = tag[2].trim();
171171

172172
if (tagName === 'return') { tagName = 'returns'; }
173173
if (tagName === 'param' || tagName === 'typeparam') {
@@ -199,7 +199,7 @@ export function parseComment(text: string, comment: Comment = new Comment()): Co
199199
}
200200

201201
if (!inCode) {
202-
const tag = /^@(\S+)/.exec(line);
202+
const tag = /^\s*@(\S+)(.*)$/.exec(line);
203203
if (tag) {
204204
return readTagLine(line, tag);
205205
}

src/test/converter/comment/comment.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,12 @@ export class CommentedClass {
4343
*/
4444
ignoredprop: string;
4545
}
46+
47+
/** Function description
48+
*
49+
* @param scope Test description.
50+
* @returns Test description.
51+
*/
52+
export function gh1164(scope: string) {
53+
return scope;
54+
}

src/test/converter/comment/specs.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,59 @@
8080
"character": 27
8181
}
8282
]
83+
},
84+
{
85+
"id": 11,
86+
"name": "gh1164",
87+
"kind": 64,
88+
"kindString": "Function",
89+
"flags": {
90+
"isExported": true
91+
},
92+
"signatures": [
93+
{
94+
"id": 12,
95+
"name": "gh1164",
96+
"kind": 4096,
97+
"kindString": "Call signature",
98+
"flags": {
99+
"isExported": true
100+
},
101+
"comment": {
102+
"shortText": "Function description",
103+
"returns": "Test description.\n"
104+
},
105+
"parameters": [
106+
{
107+
"id": 13,
108+
"name": "scope",
109+
"kind": 32768,
110+
"kindString": "Parameter",
111+
"flags": {
112+
"isExported": true
113+
},
114+
"comment": {
115+
"text": "Test description."
116+
},
117+
"type": {
118+
"type": "intrinsic",
119+
"name": "string"
120+
}
121+
}
122+
],
123+
"type": {
124+
"type": "intrinsic",
125+
"name": "string"
126+
}
127+
}
128+
],
129+
"sources": [
130+
{
131+
"fileName": "comment.ts",
132+
"line": 52,
133+
"character": 22
134+
}
135+
]
83136
}
84137
],
85138
"groups": [
@@ -89,6 +142,13 @@
89142
"children": [
90143
7
91144
]
145+
},
146+
{
147+
"title": "Functions",
148+
"kind": 64,
149+
"children": [
150+
11
151+
]
92152
}
93153
],
94154
"sources": [

0 commit comments

Comments
 (0)