leonardfactory / babel-plugin-transform-typescript-metadata

Babel plugin to emit decorator metadata like typescript compiler
MIT License
215 stars 17 forks source link

✨ add support for babel-plugin-macros #64

Open intellild opened 2 years ago

intellild commented 2 years ago

support babel-plugin-macros example:

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

@metadata
class A {}
intellild commented 2 years ago

Hi @leonardfactory can you look at this ?

intellild commented 2 years ago

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

leonardfactory commented 2 years ago

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.

intellild commented 2 years ago

@leonardfactory There are two problems.