From d28072d441e5da69aee23e062d55344a4fba79de Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sun, 12 Jan 2020 22:05:47 -0700 Subject: [PATCH] fix: `@param` / `@returns` overly sensitive to whitespace Closes #1164 --- src/lib/converter/factories/comment.ts | 4 +- src/test/converter/comment/comment.ts | 9 ++++ src/test/converter/comment/specs.json | 60 ++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/lib/converter/factories/comment.ts b/src/lib/converter/factories/comment.ts index 793e7f255..3d4726669 100644 --- a/src/lib/converter/factories/comment.ts +++ b/src/lib/converter/factories/comment.ts @@ -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') { @@ -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); } diff --git a/src/test/converter/comment/comment.ts b/src/test/converter/comment/comment.ts index fb409c3c9..af47b5852 100644 --- a/src/test/converter/comment/comment.ts +++ b/src/test/converter/comment/comment.ts @@ -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; +} diff --git a/src/test/converter/comment/specs.json b/src/test/converter/comment/specs.json index 33da1f94f..9e20563e6 100644 --- a/src/test/converter/comment/specs.json +++ b/src/test/converter/comment/specs.json @@ -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": [ @@ -89,6 +142,13 @@ "children": [ 7 ] + }, + { + "title": "Functions", + "kind": 64, + "children": [ + 11 + ] } ], "sources": [