leonardfactory / babel-plugin-transform-typescript-metadata

Babel plugin to emit decorator metadata like typescript compiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

missing class metadata in parameter-decorated classes

wtho opened this issue · comments

commented

When I transpile a simple class, which has a decorated parameter as such

class Compilee {
  constructor(@SomeDecorator() param) { }
}

then tsc will (with emitDecoratorMetadata) also set __metadata("design:paramtypes", ...) on the class itself.
This does not happen in this plugin yet.

For a reconstruction, see https://gist.github.com/wtho/0db9f9f4d224ae85d65ad9e54293abdb

Do you think this functionally could be added to this plugin?

I could give it a try, but it would probably create more coupling between the two visitors, I think you should decide how this happens.

So the issue here is with constructor arguments. Didn't know emitDecoratorMetadata handled these two. I'll check if it's possible to emit the additional decorator to the classe, I'll update you with my findings

commented

Ok great!

I just cross-checked if an application to a prop only would have a similar effect, but there is only the design:types metadata set as expected.

Had another look at the code and I think it should be quite straightforward to implement. Inside the constructor handling we still have the reference of the class itself (path) and so the Reflect.metadata can just added to the decorators as done in the metadataVisitor.