(code: string)
| 18 | } |
| 19 | |
| 20 | function getProgramPath(code: string): NodePath<t.Program> { |
| 21 | const ast = parseAst({ code }) |
| 22 | let programPath: NodePath<t.Program> | undefined |
| 23 | |
| 24 | babel.traverse(ast, { |
| 25 | Program(path: NodePath<t.Program>) { |
| 26 | programPath = path |
| 27 | path.stop() |
| 28 | }, |
| 29 | }) |
| 30 | |
| 31 | if (!programPath) { |
| 32 | throw new Error('Program path not found') |
| 33 | } |
| 34 | |
| 35 | return programPath |
| 36 | } |
| 37 | |
| 38 | describe('normalizePath', () => { |
| 39 | it('should convert Windows backslashes to forward slashes', () => { |