Find line:col of an opening JSX tag in source.
(source: string, tag: string)
| 23 | |
| 24 | /** Find line:col of an opening JSX tag in source. */ |
| 25 | function findPosition(source: string, tag: string): { line: number; col: number } { |
| 26 | const lines = source.split("\n"); |
| 27 | for (let i = 0; i < lines.length; i++) { |
| 28 | const col = lines[i].indexOf(`<${tag}`); |
| 29 | if (col !== -1) return { line: i + 1, col }; // 1-indexed line, 0-indexed col |
| 30 | } |
| 31 | throw new Error(`Tag <${tag}> not found`); |
| 32 | } |
| 33 | |
| 34 | function findMarkdownPosition(source: string, snippet: string): { line: number; col: number } { |
| 35 | const lines = source.split("\n"); |
no outgoing calls
no test coverage detected