Skip to content

Commit 5b7bf8a

Browse files
committed
feat: use onlyRemoveTypeImports
1 parent 992272d commit 5b7bf8a

File tree

1 file changed

+42
-1
lines changed
  • packages/vite/src/node/plugins

1 file changed

+42
-1
lines changed

packages/vite/src/node/plugins/oxc.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export async function transformWithOxc(
6868
ensureWatchedFile(watcher, tsconfigFile, config.root)
6969
}
7070
const loadedCompilerOptions = loadedTsconfig.compilerOptions ?? {}
71-
// tsc compiler alwaysStrict/experimentalDecorators/importsNotUsedAsValues/preserveValueImports/target/useDefineForClassFields/verbatimModuleSyntax
71+
// tsc compiler experimentalDecorators/target/useDefineForClassFields
7272

7373
resolvedOptions.jsx ??= {}
7474
if (loadedCompilerOptions.jsxFactory) {
@@ -99,6 +99,47 @@ export async function transformWithOxc(
9999
default:
100100
break
101101
}
102+
103+
/**
104+
* | preserveValueImports | importsNotUsedAsValues | verbatimModuleSyntax | onlyRemoveTypeImports |
105+
* | -------------------- | ---------------------- | -------------------- |---------------------- |
106+
* | false | remove | false | false |
107+
* | false | preserve, error | - | - |
108+
* | true | remove | - | - |
109+
* | true | preserve, error | true | true |
110+
*/
111+
if (loadedCompilerOptions.verbatimModuleSyntax !== undefined) {
112+
resolvedOptions.typescript ??= {}
113+
resolvedOptions.typescript.onlyRemoveTypeImports =
114+
loadedCompilerOptions.verbatimModuleSyntax
115+
} else if (
116+
loadedCompilerOptions.preserveValueImports !== undefined ||
117+
loadedCompilerOptions.importsNotUsedAsValues !== undefined
118+
) {
119+
const preserveValueImports =
120+
loadedCompilerOptions.preserveValueImports ?? false
121+
const importsNotUsedAsValues =
122+
loadedCompilerOptions.importsNotUsedAsValues ?? 'remove'
123+
if (
124+
preserveValueImports === false &&
125+
importsNotUsedAsValues === 'remove'
126+
) {
127+
resolvedOptions.typescript ??= {}
128+
resolvedOptions.typescript.onlyRemoveTypeImports = true
129+
} else if (
130+
preserveValueImports === true &&
131+
(importsNotUsedAsValues === 'preserve' ||
132+
importsNotUsedAsValues === 'error')
133+
) {
134+
resolvedOptions.typescript ??= {}
135+
resolvedOptions.typescript.onlyRemoveTypeImports = false
136+
} else {
137+
ctx.warn(
138+
`preserveValueImports=${preserveValueImports} + importsNotUsedAsValues=${importsNotUsedAsValues} is not supported by oxc.` +
139+
'Please migrate to the new verbatimModuleSyntax option.',
140+
)
141+
}
142+
}
102143
} catch (e) {
103144
if (e instanceof TSConfckParseError) {
104145
// tsconfig could be out of root, make sure it is watched on dev

0 commit comments

Comments
 (0)