The line that declares `name`, or the first line of code; without its opening brace.
(lines: readonly string[], name: string | undefined, fence: string)
| 118 | |
| 119 | /** The line that declares `name`, or the first line of code; without its opening brace. */ |
| 120 | function definitionLine(lines: readonly string[], name: string | undefined, fence: string): CodeFacts | undefined { |
| 121 | const code = lines.filter(line => line.trim() && !/^\s*(?:\/\/|\/\*|\*|#|--|<!--)/.test(line)); |
| 122 | const named = name ? code.find(line => new RegExp(`(?:^|[^\\w$])${escape(name)}(?:[^\\w$]|$)`).test(line)) : undefined; |
| 123 | const line = (named ?? code[0])?.trim().replace(/\s*\{\s*$/, ''); |
| 124 | return line ? { lines: [bounded(line)], more: 0, unit: 'lines', fence } : undefined; |
| 125 | } |
| 126 | |
| 127 | /** The facts of the code a selection stands for, or undefined without code. */ |
| 128 | export function codeFacts(source: { text: string; path: string }, subject?: { name: string; kind?: string }): CodeFacts | undefined { |