Skip to content

Commit

Permalink
fix: @param / @returns overly sensitive to whitespace
Browse files Browse the repository at this point in the history
Closes #1164
  • Loading branch information
Gerrit0 committed Jan 13, 2020
1 parent 6a762f0 commit d28072d
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/converter/factories/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export function parseComment(text: string, comment: Comment = new Comment()): Co
function readTagLine(line: string, tag: RegExpExecArray) {
let tagName = tag[1].toLowerCase();
let paramName: string | undefined;
line = line.substr(tagName.length + 1).trim();
line = tag[2].trim();

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

if (!inCode) {
const tag = /^@(\S+)/.exec(line);
const tag = /^\s*@(\S+)(.*)$/.exec(line);
if (tag) {
return readTagLine(line, tag);
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/converter/comment/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,12 @@ export class CommentedClass {
*/
ignoredprop: string;
}

/** Function description
*
* @param scope Test description.
* @returns Test description.
*/
export function gh1164(scope: string) {
return scope;
}
60 changes: 60 additions & 0 deletions src/test/converter/comment/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,59 @@
"character": 27
}
]
},
{
"id": 11,
"name": "gh1164",
"kind": 64,
"kindString": "Function",
"flags": {
"isExported": true
},
"signatures": [
{
"id": 12,
"name": "gh1164",
"kind": 4096,
"kindString": "Call signature",
"flags": {
"isExported": true
},
"comment": {
"shortText": "Function description",
"returns": "Test description.\n"
},
"parameters": [
{
"id": 13,
"name": "scope",
"kind": 32768,
"kindString": "Parameter",
"flags": {
"isExported": true
},
"comment": {
"text": "Test description."
},
"type": {
"type": "intrinsic",
"name": "string"
}
}
],
"type": {
"type": "intrinsic",
"name": "string"
}
}
],
"sources": [
{
"fileName": "comment.ts",
"line": 52,
"character": 22
}
]
}
],
"groups": [
Expand All @@ -89,6 +142,13 @@
"children": [
7
]
},
{
"title": "Functions",
"kind": 64,
"children": [
11
]
}
],
"sources": [
Expand Down

0 comments on commit d28072d

Please sign in to comment.