(node: ts.Node, sourceFile: ts.SourceFile)
| 80 | } |
| 81 | |
| 82 | static getTsDocCommentsForFunction(node: ts.Node, sourceFile: ts.SourceFile) { |
| 83 | const params: Record<string, string> = {}; |
| 84 | const trivia = |
| 85 | ts.getLeadingCommentRanges(sourceFile.text, node.getFullStart()) || []; |
| 86 | |
| 87 | let comment = ""; |
| 88 | |
| 89 | for (const range of trivia) { |
| 90 | const commentText = Comments.removeCommentSyntax( |
| 91 | sourceFile.text.substring(range.pos, range.end), |
| 92 | ); |
| 93 | |
| 94 | const lines = commentText.split("\n").map((line) => line.trim()); |
| 95 | |
| 96 | if (lines.length && !lines[0].startsWith("@param")) { |
| 97 | comment = lines[0]; |
| 98 | } |
| 99 | |
| 100 | lines.forEach((line) => { |
| 101 | if (line.startsWith("@param")) { |
| 102 | const parts = line.split(/\s+/); |
| 103 | if (parts.length >= 3) { |
| 104 | const paramName = parts[1]; |
| 105 | const description = parts.slice(2).join(" "); |
| 106 | params[paramName] = description.trim(); |
| 107 | } |
| 108 | } |
| 109 | }); |
| 110 | } |
| 111 | |
| 112 | return { comment, params }; |
| 113 | } |
| 114 | } |
no test coverage detected