-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Running knighted-css-generate-types --root . fails when it hits JSX. The CLI feeds each source file directly into es-module-lexer.parse(), which only understands standard JavaScript module syntax, so raw TSX causes a parse error before ?knighted-css&types imports are discovered.
Potential fixes
- Inline transpile before parsing – Run files through a lightweight transformer (esbuild, sucrase, @swc/core) to strip TypeScript/JSX down to JS, then hand the result to
parse(). - Use
typescript.transpileModule()– Invoke the TS compiler with{ module: ESNext, jsx: ReactJSX, target: ES2022 }to emit JS (React.createElement) while preserving import specifiers. - Expose a lexer override hook – Promote the internal
setLexerOverrides()helper so consumers can provide a JSX-capable parser (e.g., acorn + acorn-jsx), falling back toes-module-lexerfor plain JS. - Heuristic retry – Wrap
parse()in try/catch; if a.tsx/.jsxfile fails, run a minimal JSX-stripping pass and retry to avoid new dependencies for vanilla projects.
The goal is to pick one (or combine several) so @knighted/css can parse JSX-heavy codebases without extra setup.
For now a workaround is to use @knighted/jsx to write JSX syntax within tagged template literals.
Metadata
Metadata
Assignees
Labels
No labels