Skip to content

Commit 7ef2472

Browse files
authored
fix(esbuild): use useDefineForClassFields: false when no compilerOptions.target is declared (#13708)
1 parent 2b1ffe8 commit 7ef2472

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/vite/src/node/__tests__/plugins/esbuild.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ describe('transformWithEsbuild', () => {
378378
})
379379
expect(actual).toBe(defineForClassFieldsTrueTransformedCode)
380380
})
381+
382+
test('target: es2022 and tsconfig.target: undefined => false', async () => {
383+
const actual = await transformClassCode('es2022', {})
384+
expect(actual).toBe(defineForClassFieldsFalseTransformedCode)
385+
})
381386
})
382387
})
383388

packages/vite/src/node/plugins/esbuild.ts

+10
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ export async function transformWithEsbuild(
132132
...tsconfigRaw?.compilerOptions,
133133
}
134134

135+
// esbuild uses `useDefineForClassFields: true` when `tsconfig.compilerOptions.target` isn't declared
136+
// but we want `useDefineForClassFields: false` when `tsconfig.compilerOptions.target` isn't declared
137+
// to align with the TypeScript's behavior
138+
if (
139+
compilerOptions.useDefineForClassFields === undefined &&
140+
compilerOptions.target === undefined
141+
) {
142+
compilerOptions.useDefineForClassFields = false
143+
}
144+
135145
// esbuild uses tsconfig fields when both the normal options and tsconfig was set
136146
// but we want to prioritize the normal options
137147
if (options) {

0 commit comments

Comments
 (0)