@@ -56,6 +56,7 @@ type TSConfigJSON = {
56
56
extends ?: string
57
57
compilerOptions ?: {
58
58
alwaysStrict ?: boolean
59
+ experimentalDecorators ?: boolean
59
60
importsNotUsedAsValues ?: 'remove' | 'preserve' | 'error'
60
61
jsx ?: 'preserve' | 'react' | 'react-jsx' | 'react-jsxdev'
61
62
jsxFactory ?: string
@@ -64,6 +65,7 @@ type TSConfigJSON = {
64
65
preserveValueImports ?: boolean
65
66
target ?: string
66
67
useDefineForClassFields ?: boolean
68
+ verbatimModuleSyntax ?: boolean
67
69
}
68
70
[ key : string ] : any
69
71
}
@@ -101,6 +103,7 @@ export async function transformWithEsbuild(
101
103
// https://esbuild.github.io/content-types/#tsconfig-json
102
104
const meaningfulFields : Array < keyof TSCompilerOptions > = [
103
105
'alwaysStrict' ,
106
+ 'experimentalDecorators' ,
104
107
'importsNotUsedAsValues' ,
105
108
'jsx' ,
106
109
'jsxFactory' ,
@@ -109,6 +112,7 @@ export async function transformWithEsbuild(
109
112
'preserveValueImports' ,
110
113
'target' ,
111
114
'useDefineForClassFields' ,
115
+ 'verbatimModuleSyntax' ,
112
116
]
113
117
const compilerOptionsForFile : TSCompilerOptions = { }
114
118
if ( loader === 'ts' || loader === 'tsx' ) {
@@ -128,28 +132,13 @@ export async function transformWithEsbuild(
128
132
...tsconfigRaw ?. compilerOptions ,
129
133
}
130
134
131
- // esbuild derives `useDefineForClassFields` from `target` instead of `tsconfig.compilerOptions.target`
132
- // https://github.com/evanw/esbuild/issues/2584
133
- // but we want `useDefineForClassFields` to be derived from `tsconfig.compilerOptions.target`
134
- if ( compilerOptions . useDefineForClassFields === undefined ) {
135
- const lowercaseTarget = compilerOptions . target ?. toLowerCase ( ) ?? 'es3'
136
- if ( lowercaseTarget . startsWith ( 'es' ) ) {
137
- const esVersion = lowercaseTarget . slice ( 2 )
138
- compilerOptions . useDefineForClassFields =
139
- esVersion === 'next' || + esVersion >= 2022
140
- } else {
141
- compilerOptions . useDefineForClassFields = false
142
- }
143
- }
144
-
145
135
// esbuild uses tsconfig fields when both the normal options and tsconfig was set
146
136
// but we want to prioritize the normal options
147
137
if ( options ) {
148
138
options . jsx && ( compilerOptions . jsx = undefined )
149
139
options . jsxFactory && ( compilerOptions . jsxFactory = undefined )
150
140
options . jsxFragment && ( compilerOptions . jsxFragmentFactory = undefined )
151
141
options . jsxImportSource && ( compilerOptions . jsxImportSource = undefined )
152
- options . target && ( compilerOptions . target = undefined )
153
142
}
154
143
155
144
tsconfigRaw = {
@@ -158,19 +147,22 @@ export async function transformWithEsbuild(
158
147
}
159
148
}
160
149
161
- const resolvedOptions = {
150
+ const resolvedOptions : TransformOptions = {
162
151
sourcemap : true ,
163
152
// ensure source file name contains full query
164
153
sourcefile : filename ,
165
154
...options ,
166
155
loader,
167
156
tsconfigRaw,
168
- } as ESBuildOptions
157
+ }
169
158
170
159
// Some projects in the ecosystem are calling this function with an ESBuildOptions
171
160
// object and esbuild throws an error for extra fields
161
+ // @ts -expect-error include exists in ESBuildOptions
172
162
delete resolvedOptions . include
163
+ // @ts -expect-error exclude exists in ESBuildOptions
173
164
delete resolvedOptions . exclude
165
+ // @ts -expect-error jsxInject exists in ESBuildOptions
174
166
delete resolvedOptions . jsxInject
175
167
176
168
try {
@@ -199,6 +191,10 @@ export async function transformWithEsbuild(
199
191
if ( e . errors ) {
200
192
e . frame = ''
201
193
e . errors . forEach ( ( m : Message ) => {
194
+ if ( m . text === 'Experimental decorators are not currently enabled' ) {
195
+ m . text +=
196
+ '. Vite 4.4+ now uses esbuild 0.18 and you need to enable them by adding "experimentalDecorators": true in your "tsconfig.json" file.'
197
+ }
202
198
e . frame += `\n` + prettifyMessage ( m , code )
203
199
} )
204
200
e . loc = e . errors [ 0 ] . location
0 commit comments