monounity / karma-typescript

Simplifying running unit tests with coverage for Typescript projects.
313 stars 109 forks source link

The process of Decorator has mistake make the PropertyDescriptor with undefined value #547

Open JiaHenry opened 2 years ago

JiaHenry commented 2 years ago

Please try with the code in TypeScript Playground

or the source code: `// @experimentalDecorators function LogMethod( target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor ) { console.log(target); console.log(propertyKey); console.log(descriptor); }

class Demo { @LogMethod public static foo(bar: number) { // do nothing }

@LogMethod public foo2(bar: number) { // do nothing } }

const demo = new Demo(); Demo.foo(10); demo.foo2(12);`

The output of js with something like __decorate(([...], Demo.prototype, "foo2", null) but the karma-typescript output code like __decorate([LogMethod], Demo.prototype, 'foo2')

the missing null at end will make the code in __decorate as following: r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc make the desc keep the undefined value because undefined === null is false.

Please see bellow pictures about the output. The is the output in TypeScript Playground typescript

And the output of karma karma