(
node: ts.Node,
sourceFile: ts.SourceFile,
)
| 31 | } |
| 32 | |
| 33 | static getDefaultValueForNode( |
| 34 | node: ts.Node, |
| 35 | sourceFile: ts.SourceFile, |
| 36 | ): string | undefined { |
| 37 | const fullText = sourceFile.getFullText(); |
| 38 | const commentRanges = ts.getLeadingCommentRanges( |
| 39 | fullText, |
| 40 | node.getFullStart(), |
| 41 | ); |
| 42 | |
| 43 | if (!commentRanges) return ""; |
| 44 | let defaultValue: string | undefined = undefined; |
| 45 | |
| 46 | for (const comment of commentRanges) { |
| 47 | let commentText = fullText.substring(comment.pos, comment.end); |
| 48 | commentText = Comments.removeCommentSyntax(commentText); |
| 49 | |
| 50 | for (const line of commentText.split("\n")) { |
| 51 | if (line.includes("@default")) { |
| 52 | defaultValue = line.split("@default")[1].trim(); |
| 53 | break; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | if (defaultValue !== undefined) break; |
| 58 | } |
| 59 | |
| 60 | return defaultValue; |
| 61 | } |
| 62 | |
| 63 | static removeCommentSyntax(commentText: string): string { |
| 64 | return commentText |
no test coverage detected