Skip to content

Commit

Permalink
fix: tsconfig jsx overrides esbuild options, reverts #10374 (#10714)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Oct 30, 2022
1 parent 0ee800f commit aacf6a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
7 changes: 2 additions & 5 deletions docs/guide/features.md
Expand Up @@ -57,7 +57,7 @@ However, some libraries (e.g. [`vue`](https://github.com/vuejs/core/issues/1228)

#### `useDefineForClassFields`

Starting from Vite 2.5.0, the default value will be `true` if the TypeScript target is `ES2022` or higher including `ESNext`. It is consistent with the [behavior of `tsc` 4.3.2 and later](https://github.com/microsoft/TypeScript/pull/42663). It is also the standard ECMAScript runtime behavior.
Starting from Vite 2.5.0, the default value will be `true` if the TypeScript target is `ESNext`. It is consistent with the [behavior of `tsc` 4.3.2 and later](https://github.com/microsoft/TypeScript/pull/42663). It is also the standard ECMAScript runtime behavior.

But it may be counter-intuitive for those coming from other programming languages or older versions of TypeScript.
You can read more about the transition in the [TypeScript 3.7 release notes](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#the-usedefineforclassfields-flag-and-the-declare-property-modifier).
Expand All @@ -71,13 +71,10 @@ But a few libraries haven't transitioned to this new default yet, including [`li
#### Other Compiler Options Affecting the Build Result

- [`extends`](https://www.typescriptlang.org/tsconfig#extends)
- [`alwaysStrict`](https://www.typescriptlang.org/tsconfig#alwaysStrict)
- [`importsNotUsedAsValues`](https://www.typescriptlang.org/tsconfig#importsNotUsedAsValues)
- [`jsx`](https://www.typescriptlang.org/tsconfig#jsx)
- [`preserveValueImports`](https://www.typescriptlang.org/tsconfig#preserveValueImports)
- [`jsxFactory`](https://www.typescriptlang.org/tsconfig#jsxFactory)
- [`jsxFragmentFactory`](https://www.typescriptlang.org/tsconfig#jsxFragmentFactory)
- [`jsxImportSource`](https://www.typescriptlang.org/tsconfig#jsxImportSource)
- [`preserveValueImports`](https://www.typescriptlang.org/tsconfig#preserveValueImports)

If migrating your codebase to `"isolatedModules": true` is an unsurmountable effort, you may be able to get around it with a third-party plugin such as [rollup-plugin-friendly-type-imports](https://www.npmjs.com/package/rollup-plugin-friendly-type-imports). However, this approach is not officially supported by Vite.

Expand Down
20 changes: 7 additions & 13 deletions packages/vite/src/node/plugins/esbuild.ts
Expand Up @@ -50,15 +50,12 @@ export type ESBuildTransformResult = Omit<TransformResult, 'map'> & {
type TSConfigJSON = {
extends?: string
compilerOptions?: {
alwaysStrict?: boolean
importsNotUsedAsValues?: 'remove' | 'preserve' | 'error'
jsx?: 'react' | 'react-jsx' | 'react-jsxdev' | 'preserve'
target?: string
jsxFactory?: string
jsxFragmentFactory?: string
jsxImportSource?: string
preserveValueImports?: boolean
target?: string
useDefineForClassFields?: boolean
importsNotUsedAsValues?: 'remove' | 'preserve' | 'error'
preserveValueImports?: boolean
}
[key: string]: any
}
Expand Down Expand Up @@ -95,15 +92,12 @@ export async function transformWithEsbuild(
// these fields would affect the compilation result
// https://esbuild.github.io/content-types/#tsconfig-json
const meaningfulFields: Array<keyof TSCompilerOptions> = [
'alwaysStrict',
'importsNotUsedAsValues',
'jsx',
'target',
'jsxFactory',
'jsxFragmentFactory',
'jsxImportSource',
'preserveValueImports',
'target',
'useDefineForClassFields'
'useDefineForClassFields',
'importsNotUsedAsValues',
'preserveValueImports'
]
const compilerOptionsForFile: TSCompilerOptions = {}
if (loader === 'ts' || loader === 'tsx') {
Expand Down

0 comments on commit aacf6a4

Please sign in to comment.