The value of useDefineForClassFields in tsconfig.json is ignored when creating the SWC config.
Reproduction
tsconfig.json
{
"compilerOptions": {
"useDefineForClassFields": false
}
}
index.ts
class Class {
static staticField;
field;
}
const instance = new Class();
console.log(instance)
console.log(Class)
Expected behaviour
When running node -r @swc-node/register ./index.ts, index.ts is transpiled with the SWC option useDefineForClassFields: false and logs the following output:
useDefineForClassFields should be set in the SWC config based on the behaviour specified at https://www.typescriptlang.org/tsconfig#useDefineForClassFields, i.e.:
If the value of useDefineForClassFields is set in tsconfig.json, use that value.
Otherwise, if the target is ES2022 or later, use true.
Otherwise, use false.
Actual behaviour
Regardless of the setting for target or useDefineForClassFields, index.ts is transpiled without passing the useDefineForClassFields option to SWC, defaults to useDefineForClassFields: true and logs the following output:
Class { field: undefined }
[class Class] { staticField: undefined }
The value of
useDefineForClassFieldsintsconfig.jsonis ignored when creating the SWC config.Reproduction
tsconfig.json
index.ts
Expected behaviour
When running
node -r @swc-node/register ./index.ts,index.tsis transpiled with the SWC optionuseDefineForClassFields: falseand logs the following output:useDefineForClassFieldsshould be set in the SWC config based on the behaviour specified at https://www.typescriptlang.org/tsconfig#useDefineForClassFields, i.e.:If the value of
useDefineForClassFieldsis set intsconfig.json, use that value.Otherwise, if the target is ES2022 or later, use
true.Otherwise, use
false.Actual behaviour
Regardless of the setting for
targetoruseDefineForClassFields,index.tsis transpiled without passing theuseDefineForClassFieldsoption to SWC, defaults touseDefineForClassFields: trueand logs the following output: