Skip to content

useDefineForClassFields value changed from 3.1 when it's derived from target #10296

@sapphi-red

Description

@sapphi-red

Describe the bug

When useDefineForClassFields is not set in tsconfig, the value is derived from target.
When target is ES2022+ or ESNext, useDefineForClassFields is true otherwise it's false.

This is documented here as well.
But it seems this was not working and still not working in some cases.

related: #10167, #10292

tsconfig.compilerOptions.target = 'ESNext' && build.target = 'ESNext'

Vite esbuild command resolved useDefineForClassFields
3.0.9 0.14.47 dev false
3.0.9 0.14.47 build false
3.1.4 0.15.10 dev true
3.1.4 0.15.10 build true

The behavior changed but I think the new behavior is correct.

tsconfig.compilerOptions.target = 'ES2021' && build.target = 'ES2021'

Vite esbuild command resolved useDefineForClassFields
3.0.9 0.14.47 dev false
3.0.9 0.14.47 build false
3.1.4 0.15.10 dev true
3.1.4 0.15.10 build true

The behavior changed and I think the new behavior is not correct.

tsconfig.compilerOptions.target = 'ESNext' && build.target = 'ES2021'

Vite esbuild command resolved useDefineForClassFields
3.0.9 0.14.47 dev false
3.0.9 0.14.47 build false
3.1.4 0.15.10 dev true
3.1.4 0.15.10 build true

The behavior changed but I think the new behavior is correct.

tsconfig.compilerOptions.target = 'ES2021' && build.target = 'ESNext'

Vite esbuild command resolved useDefineForClassFields
3.0.9 0.14.47 dev false
3.0.9 0.14.47 build false
3.1.4 0.15.10 dev true
3.1.4 0.15.10 build true

The behavior changed and I think the new behavior is not correct.
I think useDefineForClassFields should be derived from tsconfig.compilerOptions.target and not from build.target.

related esbuild's behavior

Before esbuild 0.15.8, esbuild derived useDefineForClassFields from build.target and not from tsconfig.compilerOptions.target. But from 0.15.8, it seems the behavior changed.
When target = 'es2021' + tsconfig.compilerOptions.target = 'esnext', I think the new behavior is correct.
When target = 'esnext' + tsconfig.compilerOptions.target = 'es2021', I think the behavior might not be correct.

esbuild repl 0.15.7 target = 'es2021' + tsconfig.compilerOptions.target = 'esnext'
esbuild repl 0.15.8 target = 'es2021' + tsconfig.compilerOptions.target = 'esnext'

esbuild repl 0.15.7 target = 'esnext' + tsconfig.compilerOptions.target = 'es2021'
esbuild repl 0.15.8 target = 'esnext' + tsconfig.compilerOptions.target = 'es2021'

Reproduction

https://stackblitz.com/edit/vitejs-vite-tkrvzm (Vite 3.0.9 && tsconfig.compilerOptions.target = 'ESNext' && build.target = 'ES2021')

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    vite: ~3.0.0 => 3.0.9

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p4-importantViolate documented behavior or significantly improves performance (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions