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

transformer: typescript --useDefineForClassFields #6735

Closed
Boshen opened this issue Oct 21, 2024 · 9 comments
Closed

transformer: typescript --useDefineForClassFields #6735

Boshen opened this issue Oct 21, 2024 · 9 comments
Assignees
Labels
C-enhancement Category - New feature or request needs-discussion Requires a discussion from the core team

Comments

@Boshen
Copy link
Member

Boshen commented Oct 21, 2024

https://www.typescriptlang.org/tsconfig/#useDefineForClassFields

https://babeljs.io/docs/babel-plugin-transform-typescript

  • --useDefineForClassFields You can use the setPublicClassFields assumption to replicate this behavior.

pub set_public_class_fields: bool,

@Boshen Boshen added the C-enhancement Category - New feature or request label Oct 21, 2024
@Boshen Boshen self-assigned this Oct 21, 2024
@Boshen Boshen added the needs-discussion Requires a discussion from the core team label Oct 21, 2024
@Boshen Boshen added this to the Transformer Milestone 2 milestone Oct 21, 2024
@Boshen Boshen assigned overlookmotel and unassigned Boshen Oct 21, 2024
@Boshen
Copy link
Member Author

Boshen commented Nov 25, 2024

Done in #7011 with setPublicClassFields.

@Boshen Boshen closed this as completed Nov 25, 2024
@sapphi-red
Copy link
Contributor

@Boshen Can we reopen this issue as the transform is now disabled? (#7486)
Or should I check #4754?

@sapphi-red
Copy link
Contributor

Is there a way to transform public fields with useDefineForClassFields: false and also keep other class field features as-is? For example, when a user has useDefineForClassFields: false and target: 'es2024'.

Boshen pushed a commit that referenced this issue Dec 3, 2024
so that I can use `setPublicClassFields` for #6735 when it's ready.
@Boshen
Copy link
Member Author

Boshen commented Dec 3, 2024

Is there a way to transform public fields with useDefineForClassFields: false and also keep other class field features as-is? For example, when a user has useDefineForClassFields: false and target: 'es2024'.

Not at present.

@overlookmotel
Copy link
Contributor

Is there a way to transform public fields with useDefineForClassFields: false and also keep other class field features as-is? For example, when a user has useDefineForClassFields: false and target: 'es2024'.

What's the use case for transforming public fields, but not private fields?

@sapphi-red
Copy link
Contributor

sapphi-red commented Dec 3, 2024

Is there a way to transform public fields with useDefineForClassFields: false and also keep other class field features as-is? For example, when a user has useDefineForClassFields: false and target: 'es2024'.

What's the use case for transforming public fields, but not private fields?

When a library you depend relies on the useDefineForClassFields: false behavior, but you don't need to transpile everything down to es2021. TypeScript and esbuild both supports this: typescript playground, esbuild try
I don't have a real world case, but I guess there are, because angular sets this by default and lit suggests to set it.

@overlookmotel
Copy link
Contributor

Thanks for the links. I am guessing from lit's docs that this has something to do with decorators, which we've not tackled yet.

This is going to be tricky. How much of a blocker is it?

@sapphi-red
Copy link
Contributor

Both angular and lit sets useDefineForClassFields: false to make decorators work nicely so I guess it won't be a problem until decorators are supported by oxc. I think I can just set the target to es2021 and show a warning that the target was changed for now. Vite has been recommending setting useDefineForClassFields: true regardless of the target and that should reduce the number of affected users.

@overlookmotel
Copy link
Contributor

Just FYI, in case it wasn't clear: Any code which contains decorators currently will not run, because Oxc doesn't transform decorators, and most JS runtimes don't support decorators natively. useDefineForClassFields will not save us!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category - New feature or request needs-discussion Requires a discussion from the core team
Projects
None yet
Development

No branches or pull requests

3 participants