@@ -56,6 +56,7 @@ type TSConfigJSON = {
5656 extends ?: string
5757 compilerOptions ?: {
5858 alwaysStrict ?: boolean
59+ experimentalDecorators ?: boolean
5960 importsNotUsedAsValues ?: 'remove' | 'preserve' | 'error'
6061 jsx ?: 'preserve' | 'react' | 'react-jsx' | 'react-jsxdev'
6162 jsxFactory ?: string
@@ -64,6 +65,7 @@ type TSConfigJSON = {
6465 preserveValueImports ?: boolean
6566 target ?: string
6667 useDefineForClassFields ?: boolean
68+ verbatimModuleSyntax ?: boolean
6769 }
6870 [ key : string ] : any
6971}
@@ -101,6 +103,7 @@ export async function transformWithEsbuild(
101103 // https://esbuild.github.io/content-types/#tsconfig-json
102104 const meaningfulFields : Array < keyof TSCompilerOptions > = [
103105 'alwaysStrict' ,
106+ 'experimentalDecorators' ,
104107 'importsNotUsedAsValues' ,
105108 'jsx' ,
106109 'jsxFactory' ,
@@ -109,6 +112,7 @@ export async function transformWithEsbuild(
109112 'preserveValueImports' ,
110113 'target' ,
111114 'useDefineForClassFields' ,
115+ 'verbatimModuleSyntax' ,
112116 ]
113117 const compilerOptionsForFile : TSCompilerOptions = { }
114118 if ( loader === 'ts' || loader === 'tsx' ) {
@@ -128,28 +132,13 @@ export async function transformWithEsbuild(
128132 ...tsconfigRaw ?. compilerOptions ,
129133 }
130134
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-
145135 // esbuild uses tsconfig fields when both the normal options and tsconfig was set
146136 // but we want to prioritize the normal options
147137 if ( options ) {
148138 options . jsx && ( compilerOptions . jsx = undefined )
149139 options . jsxFactory && ( compilerOptions . jsxFactory = undefined )
150140 options . jsxFragment && ( compilerOptions . jsxFragmentFactory = undefined )
151141 options . jsxImportSource && ( compilerOptions . jsxImportSource = undefined )
152- options . target && ( compilerOptions . target = undefined )
153142 }
154143
155144 tsconfigRaw = {
@@ -158,19 +147,22 @@ export async function transformWithEsbuild(
158147 }
159148 }
160149
161- const resolvedOptions = {
150+ const resolvedOptions : TransformOptions = {
162151 sourcemap : true ,
163152 // ensure source file name contains full query
164153 sourcefile : filename ,
165154 ...options ,
166155 loader,
167156 tsconfigRaw,
168- } as ESBuildOptions
157+ }
169158
170159 // Some projects in the ecosystem are calling this function with an ESBuildOptions
171160 // object and esbuild throws an error for extra fields
161+ // @ts -expect-error include exists in ESBuildOptions
172162 delete resolvedOptions . include
163+ // @ts -expect-error exclude exists in ESBuildOptions
173164 delete resolvedOptions . exclude
165+ // @ts -expect-error jsxInject exists in ESBuildOptions
174166 delete resolvedOptions . jsxInject
175167
176168 try {
@@ -199,6 +191,10 @@ export async function transformWithEsbuild(
199191 if ( e . errors ) {
200192 e . frame = ''
201193 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+ }
202198 e . frame += `\n` + prettifyMessage ( m , code )
203199 } )
204200 e . loc = e . errors [ 0 ] . location
0 commit comments