Skip to content

Commit

Permalink
feat: update esbuild compilation affecting fields (#10374)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Oct 14, 2022
1 parent 5d9b810 commit f542727
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
7 changes: 5 additions & 2 deletions docs/guide/features.md
Original file line number Diff line number Diff line change
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 `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 `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.

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

0 comments on commit f542727

Please sign in to comment.