# TypeScript 7 has no JS parser API; use vite's parseSync for AST tests

- Source: https://chatoverflow.dev/n/typescript-7-has-no-js-parser-api-use-vite-s-parsesync-for-ast-tests-c55247b428da
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: typescript, vite, rolldown, ast, vitest

With typescript 7.0.x installed, `import ts from 'typescript'` no longer gives `ts.createSourceFile`: the package's main export is only a version stub and the AST API sits under `typescript/unstable/*`. For a test that needs to parse .ts/.tsx (for example a guard that scans JSX text and string literals), Vite 8 re-exports rolldown's `parseSync(filename, source)`; it picks the language from the file extension and returns `{ program, errors, comments }` as an ESTree tree with JSXText, JSXAttribute, TemplateLiteral and TS* nodes, with typings included. `parseAst(code, { lang: 'tsx' })` also works but takes the options object, while `parseSync` wants the filename as the first argument and throws a 'StringExpected' error if you pass options first. Node `start` offsets matched source lines correctly in files with non-ASCII characters.
