Skip to content

Commit

Permalink
feat: use onlyRemoveTypeImports
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Nov 22, 2024
1 parent acc4e78 commit 756a319
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion packages/vite/src/node/plugins/oxc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function transformWithOxc(
ensureWatchedFile(watcher, tsconfigFile, config.root)
}
const loadedCompilerOptions = loadedTsconfig.compilerOptions ?? {}
// tsc compiler alwaysStrict/experimentalDecorators/importsNotUsedAsValues/preserveValueImports/target/useDefineForClassFields/verbatimModuleSyntax
// tsc compiler experimentalDecorators/target/useDefineForClassFields

resolvedOptions.jsx ??= {}
if (loadedCompilerOptions.jsxFactory) {
Expand Down Expand Up @@ -99,6 +99,47 @@ export async function transformWithOxc(
default:
break
}

/**
* | preserveValueImports | importsNotUsedAsValues | verbatimModuleSyntax | onlyRemoveTypeImports |
* | -------------------- | ---------------------- | -------------------- |---------------------- |
* | false | remove | false | false |
* | false | preserve, error | - | - |
* | true | remove | - | - |
* | true | preserve, error | true | true |
*/
if (loadedCompilerOptions.verbatimModuleSyntax !== undefined) {
resolvedOptions.typescript ??= {}
resolvedOptions.typescript.onlyRemoveTypeImports =
loadedCompilerOptions.verbatimModuleSyntax
} else if (
loadedCompilerOptions.preserveValueImports !== undefined ||
loadedCompilerOptions.importsNotUsedAsValues !== undefined
) {
const preserveValueImports =
loadedCompilerOptions.preserveValueImports ?? false
const importsNotUsedAsValues =
loadedCompilerOptions.importsNotUsedAsValues ?? 'remove'
if (
preserveValueImports === false &&
importsNotUsedAsValues === 'remove'
) {
resolvedOptions.typescript ??= {}
resolvedOptions.typescript.onlyRemoveTypeImports = true
} else if (
preserveValueImports === true &&
(importsNotUsedAsValues === 'preserve' ||
importsNotUsedAsValues === 'error')
) {
resolvedOptions.typescript ??= {}
resolvedOptions.typescript.onlyRemoveTypeImports = false
} else {
ctx.warn(
`preserveValueImports=${preserveValueImports} + importsNotUsedAsValues=${importsNotUsedAsValues} is not supported by oxc.` +
'Please migrate to the new verbatimModuleSyntax option.',
)
}
}
} catch (e) {
if (e instanceof TSConfckParseError) {
// tsconfig could be out of root, make sure it is watched on dev
Expand Down

0 comments on commit 756a319

Please sign in to comment.