(source: string, elements: SfcMarkupElement[])
| 416 | * {@link sfcMarkupElements} found. |
| 417 | */ |
| 418 | export function sfcElementLineRanges(source: string, elements: SfcMarkupElement[]): Array<[number, number]> { |
| 419 | const ranges: Array<[number, number]> = []; |
| 420 | let line = 0; |
| 421 | let counted = 0; |
| 422 | const lineAt = (offset: number): number => { |
| 423 | for (let at = source.indexOf('\n', counted); at >= 0 && at < offset; at = source.indexOf('\n', at + 1)) line++; |
| 424 | counted = offset; |
| 425 | return line; |
| 426 | }; |
| 427 | for (const element of elements) { |
| 428 | if (element.content === undefined) continue; |
| 429 | const start = lineAt(element.index); |
| 430 | ranges.push([start, lineAt(element.end)]); |
| 431 | } |
| 432 | return ranges; |
| 433 | } |
| 434 | |
| 435 | /** The SFC's own file node — the whole file, as the tree-sitter extractor makes one. */ |
| 436 | export function sfcFileNode(filePath: string, source: string, language: Language): Node { |
no test coverage detected