-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
feat(plugin-react): add decorators
option
#5050
Conversation
Using decorator syntax is common enough to warrant an easier way to enable it. **Before:** ```js react({ babel: { parserOpts: { plugins: [decorator-legacy] } } }) ``` …or by using https://babeljs.io/docs/en/babel-plugin-syntax-decorators **After:** ```js react({ decorators: { legacy: true }, // or decorators: { beforeExport: true || false }, }) ```
I don't think "common" usage is enough to justify a shorthand option.
|
Hi @sodatea
Hmm, this argument isn't very convincing IMO. ^^ Could you explain the negative outcomes you foresee? Esbuild supports decorators with no configuration, so only a parser plugin is needed for decorators to work with In fact, I wonder if enabling decorator syntax by default would cause any issues? If not, we should do that. Side note: I just learned that Esbuild implements TypeScript's decorator syntax (source), so the edit: Here are the alleged differences between Babel's legacy decorators and TypeScript's decorators:
|
Since Esbuild supports TypeScript decorators by default, I suggest we enable |
Largely the same reason that esbuild only supports TypeScript decorator but not the JavaScript decorator syntax.
|
So I've opened #5057 for automatic Babel support for decorators when
Okay, due to the differences between Babel legacy decorators and TypeScript decorators, I think we should just recommend using Babel to transform decorators (with this plugin), instead of only adding the Babel parser plugin. This will avoid any confusion. |
Using decorator syntax is common enough to warrant an easier way to enable it.
Before:
…or by using https://babeljs.io/docs/en/babel-plugin-syntax-decorators
After: