| 1 | import type { Node } from 'ts-morph' |
| 2 | |
| 3 | export const getNodeRange = (node: Node) => { |
| 4 | const src = node.getSourceFile() |
| 5 | const [startPosition, endPosition] = [node.getStart(), node.getEnd()] |
| 6 | |
| 7 | const startInfo = src.getLineAndColumnAtPos(startPosition) |
| 8 | const endInfo = src.getLineAndColumnAtPos(endPosition) |
| 9 | |
| 10 | return { |
| 11 | startPosition, |
| 12 | startLineNumber: startInfo.line, |
| 13 | startColumn: startInfo.column, |
| 14 | endPosition, |
| 15 | endLineNumber: endInfo.line, |
| 16 | endColumn: endInfo.column, |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | export type NodeRange = ReturnType<typeof getNodeRange> |