(nodePath: NodePath)
| 3 | import { traverse } from "../babel-interop"; |
| 4 | |
| 5 | export function getAstKey(nodePath: NodePath) { |
| 6 | const keyChunks: any[] = []; |
| 7 | |
| 8 | let current: NodePath | null = nodePath; |
| 9 | while (current) { |
| 10 | keyChunks.push(current.key); |
| 11 | current = current.parentPath; |
| 12 | |
| 13 | if (t.isProgram(current?.node)) { |
| 14 | break; |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | const result = keyChunks.reverse().join("/"); |
| 19 | return result; |
| 20 | } |
| 21 | |
| 22 | export function getAstByKey(ast: t.File, key: string) { |
| 23 | const programPath = _getProgramNodePath(ast); |
no test coverage detected