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

Expose use_define_for_class_fields in SWC config #3317

Closed
cafreeman opened this issue Jan 19, 2022 · 4 comments · Fixed by #3766
Closed

Expose use_define_for_class_fields in SWC config #3317

cafreeman opened this issue Jan 19, 2022 · 4 comments · Fixed by #3766
Milestone

Comments

@cafreeman
Copy link

Describe the feature

When compiling a class with class fields using TypeScript syntax, SWC currently down-levels class fields no matter what version of JS is being targeted.

In other words, this:

class Foo {
  foo = 'foo';
}

gets turned into this:

class Foo {
    constructor(){
        this.foo = 'foo';
    }
}

no matter what config options you use.

However, the capability to avoid this down-leveling already exists in SWC (and is even tested!) but is unfortunately simply not exposed as a config option in the the SWC config itself.

Could you please provide a way to actually enable this feature in the SWC config?

Babel plugin or link to the feature description

No response

Additional context

No response

@kdy1 kdy1 added this to the v1.2.134 milestone Jan 20, 2022
@magic-akari
Copy link
Member

setPublicClassFields

@cafreeman
Copy link
Author

Hmmm, interesting, but both Babel and SWC preserve class fields when targeting the latest version of ES. SWC only tweaks the class fields when using the TypeScript syntax, so I'm not sure this assumption is playing a role here.

@Austaras
Copy link
Member

No, typescript has its seperate class field transform pass

@kdy1 kdy1 modified the milestones: v1.2.134, v1.2.135, v1.2.136 Jan 25, 2022
@kdy1 kdy1 modified the milestones: v1.2.136, v1.2.137, v1.2.138, v1.2.139 Feb 3, 2022
@kdy1 kdy1 modified the milestones: v1.2.143, v1.2.144, v1.2.145, v1.2.146 Feb 19, 2022
@kdy1 kdy1 removed this from the v1.2.146 milestone Feb 27, 2022
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 18, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging a pull request may close this issue.

5 participants