Skip to content

Value of useDefineForClassFields in tsconfig is ignored when creating SWC config #739

Description

@dsyddall

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:

Class {}
[class Class]

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 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions