-
Notifications
You must be signed in to change notification settings - Fork 58
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
Support TC39 decorators (TS 5, esbuild 0.21, Vite 5.3) #86
Comments
I'm not sure the referenced issue is going to be closed out however Evan posted this update stating parsing decorators was working: evanw/esbuild#104 (comment) I have also patched this package with |
I've been using this without issue since posting the prior comment. Any interest in a PR to get this into the plugin? |
Looking into this further, the latest versions of SWC do not require specifying the decorator support version. They have moved to Stage 3 as the default decorator version and have introduced new options to switch back to legacy TS decorators. So, updating to the latest SWC and adjusting the documentation would be a way forward. |
I was waiting for a stable lowering of the new spec to ship in esbuild to change the behaviour of the plugin, so that people can use them in dev and don't need to bump to much they prod target. Edit: https://github.com/evanw/decorator-tests was updated 2 days ago, I hope Evan will find a implementation that he is ok to ship to esbuild! |
update: it's shipped in esbuild |
Yep I saw that, I'll look at a new API for the plugin once 0.21 is shipped by Vite |
Hello, I'm not very clear about what swc is responsible for when esbuild is. swc is similar to babel, so syntax downgrade is swc's responsibility. Why does esbuild also have downgrade operations? |
@vaynevayne I personally use SWC for dev and build, but the default at least a while back was for SWC to only be used for dev and esbuild used for build. |
@vaynevayne esbuild is both a bundler (aggregating multiple JS files into bigger JS outputs) and a transformer (transforming one TS(X) file into JS, while potentially downgrading if enabled). It can do most of what SWC and Babel do, and this is why this is currently the default transformer used by Vite. But because esbuild doesn't support fast refresh, we need to use either babel or SWC for React plugins. For me it's better to keep SWC usage only in development and let the default |
thanks You made it very clear |
How to use decorator syntax in JSX? In Vite 5.3 |
I have been patching this for over a year via pnpm:
|
thanks, had to ask chatgpt how to do that in my npm project and found out that |
I just found this -- would be great to have support, as decorators are very nice. |
While waiting for vite support, I'd like to point out the following answer to another thread as a reference on how to use stage 3 decorators in vite. It is easy to get lost in decorators' issues, I hope this will help somebody. |
@andeeplus if you do just that you will loose HMR. Maybe running both with this one first will works but not guarantee. Reminder: The future of Vite is OXC and opting into a still not fully standard decorator transform that is not fully complete is not something we plan to support long term and that's why I don't want to make it one flag away or the default for now. |
@ArnaudBarre Thanks for the tips, I've read in several places about the patch but I'm not really sure on what to patch really. I can see an example above but it's not very clear about what to patch. For instance in my current project I'm not using react and if I'm not wrong the patch above is referred to the swc-react plugin and it basically adds In any case I was having weird behaviours with the solution I posted above and checking the test suite in the issue that you post in your latest comment I've realized why: the swc transformation unfortunately is not very accurate. So I took a more naive approach and for my use case the following is more than enough:
Thanks for your time. |
Update: Support for TC39 decorators has been shipped in esbuild 0.21, included in Vite 5.3.
SWC support is still not fully there, see swc-project/swc#8970
As the goal of this plugin was since the beginning to enforce good practice and be transpiler agnostic (OXC is coming 👀), I'm still waiting before adding support to the plugin.
In the meantime, you can easily patch the library if you want to opt-in into the use of an unstable feature
The text was updated successfully, but these errors were encountered: