vitejs / vite-plugin-react-swc

Speed up your Vite dev server with SWC
MIT License
831 stars 54 forks source link

Option to disable `useDefineForClassFields` #69

Closed marcelgerber closed 1 year ago

marcelgerber commented 1 year ago

Hi,

this is a great project and is way faster than the Babel React plugin, which is amazing 🙌🏻

However, when trying it out, I ran into an issue where decorators and useDefineForClassFields don't always work well together. This is known in the TypeScript repo (see https://github.com/microsoft/TypeScript/issues/35081) and expected behavior, but still it can end up breaking apps that work perfectly well otherwise.

And, in fact, it seems that exactly this problem is happening for me: My app doesn't work correctly with useDefineForClassFields enabled, but when I disable it, it works just fine (and is very fast!).

For this reason, I would like there to be an option to disable the flag.

CHOYSEN commented 1 year ago

hi @ArnaudBarre, what do you think of this? It is very helpful for migrating projects that use a lot of decorators, PR welcome?

ArnaudBarre commented 1 year ago

Hello,

Yep this change in the spec is really annoying, but we think this is not a good idea to make it too simple for people to keep using on this old spec. The new tools in few years will probably not support it and you will not be able to ship them directly to the browser when this is implemented.

If you really want to use the plugin before updating your code, a one line patch is enough (you need to update this line in the cjs or esm compiled version).