Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dsyddall opened this issue Nov 12, 2023 · 0 comments · Fixed by #740
Closed

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

dsyddall opened this issue Nov 12, 2023 · 0 comments · Fixed by #740

Comments

@dsyddall
Copy link
Contributor

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 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant