Skip to content

Commit 0608e92

Browse files
committed
fix(parser): normalize tsconfig compiler options for ts-morph
TS 6.0 (bundled in ts-morph@28 via @ts-morph/common@0.29) refuses raw JSON compilerOptions with string-form enum values like target: "ESNext", throwing: target is a string value; tsconfig JSON must be parsed with parseJsonSourceFileConfigFileContent or getParsedCommandLineOfConfigFile before passing to createProgram Run compilerOptions through ts.convertCompilerOptionsFromJson before handing them to ts-morph's Project, so string enums are converted to their numeric form.
1 parent 055e69c commit 0608e92

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@pandacss/parser': patch
3+
---
4+
5+
Normalize tsconfig `compilerOptions` before passing them to ts-morph.
6+
7+
TypeScript 6.0 (bundled inside `ts-morph@28` via `@ts-morph/common@0.29`) now refuses to accept
8+
raw JSON `compilerOptions` with string-form enum values like `target: "ESNext"`. They must be
9+
converted to numeric enum values via the TypeScript parser API.
10+
11+
Previously, panda forwarded the parsed-as-JSON `compilerOptions` from `get-tsconfig` straight
12+
to ts-morph, which caused `panda` (codegen and any command that loads source files) to throw:
13+
14+
```
15+
target is a string value; tsconfig JSON must be parsed with parseJsonSourceFileConfigFileContent
16+
or getParsedCommandLineOfConfigFile before passing to createProgram
17+
```
18+
19+
We now run `compilerOptions` through `ts.convertCompilerOptionsFromJson` so string enums are
20+
normalized before ts-morph instantiates its TypeScript program.

packages/parser/src/project.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,21 @@ import {
1212
ScriptKind,
1313
SourceFile,
1414
Project as TsProject,
15+
ts,
1516
type ProjectOptions as TsProjectOptions,
1617
} from 'ts-morph'
1718
import { classifyProject } from './classify'
1819
import { createParser } from './parser'
1920
import { ParserResult } from './parser-result'
2021

22+
// TS 6.0 rejects raw JSON compiler options (e.g. `target: "ESNext"`) in createProgram.
23+
// They must be normalized to numeric enum values via TypeScript's own parser API first.
24+
const normalizeCompilerOptions = (raw: ts.CompilerOptions | undefined): ts.CompilerOptions => {
25+
if (!raw) return {}
26+
const { options } = ts.convertCompilerOptionsFromJson(raw, process.cwd())
27+
return options
28+
}
29+
2130
const createTsProject = (options: Partial<TsProjectOptions>) =>
2231
new TsProject({
2332
skipAddingFilesFromTsConfig: true,
@@ -28,7 +37,7 @@ const createTsProject = (options: Partial<TsProjectOptions>) =>
2837
allowJs: true,
2938
strictNullChecks: false,
3039
skipLibCheck: true,
31-
...options.compilerOptions,
40+
...normalizeCompilerOptions(options.compilerOptions),
3241
},
3342
})
3443

0 commit comments

Comments
 (0)