babel-plugin-transform-typescript-metadata icon indicating copy to clipboard operation
babel-plugin-transform-typescript-metadata copied to clipboard

✨ add support for babel-plugin-macros

Open intellild opened this issue 3 years ago • 4 comments

support babel-plugin-macros example:

import metadata from "babel-plugin-transform-typescript-metadata/lib/macro";

@metadata
class A {}

intellild avatar Feb 24 '22 09:02 intellild

Hi @leonardfactory can you look at this ?

intellild avatar Feb 25 '22 02:02 intellild

@leonardfactory I made the babel-plugin-macros dependency optional

intellild avatar Mar 11 '22 08:03 intellild

Hi @intellild, I didn't have time to analyze this correctly before; now I'm wondering which use case you are trying to cover here. I'm genuinely curious about your proposal, I'll try to explain my point of view. The plugin works well when you need to work with Reflect.metadata outputs, and this usually requires every decorated class / property / etc. to be processed: in this situation so, manually decorating everything could be cumbersome, and it can be considered an implicit side effect and, like babel-plugin-macros already states:

Explicit is often a better pattern than implicit because it requires others to understand how things are globally configured. This is in this spirit are babel-plugin-macros designed. However, some things do need to be implicit, and those kinds of babel plugins can't be turned into macros.

Furtermore this plugin tries to emulate (with a best-effort strategy) the official TypeScript feature --emitDecoratorMetadata, which is implict too.

Given all of that, I'm curious about the macro usage and I'd like to hear back from you before including it in the package – I'm just worried it could bring a bit of confusion to future and existing users.

leonardfactory avatar Mar 15 '22 21:03 leonardfactory

@leonardfactory There are two problems.

  • The project boilerplate may not support adding babel plugins, such as create-react-app
  • I don't want to affect some one else's code in a huge project which maybe more than one hundred people is working on, while the macro marks classes that need metadata explicitly

intellild avatar Mar 17 '22 10:03 intellild