( name: string, props?: (...args: any[]) => any, parentClass?: any, additionalProcessing?: (type: Type<T>) => void, typeFn?: (type: Type<T>, ...args: any[]) => void, )
| 45 | * @suppress {globalThis} |
| 46 | */ |
| 47 | export function makeDecorator<T>( |
| 48 | name: string, |
| 49 | props?: (...args: any[]) => any, |
| 50 | parentClass?: any, |
| 51 | additionalProcessing?: (type: Type<T>) => void, |
| 52 | typeFn?: (type: Type<T>, ...args: any[]) => void, |
| 53 | ): {new (...args: any[]): any; (...args: any[]): any; (...args: any[]): (cls: any) => any} { |
| 54 | return noSideEffects(() => { |
| 55 | const metaCtor = makeMetadataCtor(props); |
| 56 | |
| 57 | function DecoratorFactory( |
| 58 | this: unknown | typeof DecoratorFactory, |
| 59 | ...args: any[] |
| 60 | ): (cls: Type<T>) => any { |
| 61 | if (this instanceof DecoratorFactory) { |
| 62 | metaCtor.call(this, ...args); |
| 63 | return this as typeof DecoratorFactory; |
| 64 | } |
| 65 | |
| 66 | const annotationInstance = new (DecoratorFactory as any)(...args); |
| 67 | return function TypeDecorator(cls: Type<T>) { |
| 68 | if (typeFn) typeFn(cls, ...args); |
| 69 | // Use of Object.defineProperty is important since it creates non-enumerable property which |
| 70 | // prevents the property is copied during subclassing. |
| 71 | const annotations = cls.hasOwnProperty(ANNOTATIONS) |
| 72 | ? (cls as any)[ANNOTATIONS] |
| 73 | : (Object.defineProperty(cls, ANNOTATIONS, {value: []}) as any)[ANNOTATIONS]; |
| 74 | annotations.push(annotationInstance); |
| 75 | |
| 76 | if (additionalProcessing) additionalProcessing(cls); |
| 77 | |
| 78 | return cls; |
| 79 | }; |
| 80 | } |
| 81 | |
| 82 | if (parentClass) { |
| 83 | DecoratorFactory.prototype = Object.create(parentClass.prototype); |
| 84 | } |
| 85 | |
| 86 | DecoratorFactory.prototype.ngMetadataName = name; |
| 87 | (DecoratorFactory as any).annotationCls = DecoratorFactory; |
| 88 | return DecoratorFactory as any; |
| 89 | }); |
| 90 | } |
| 91 | |
| 92 | function makeMetadataCtor(props?: (...args: any[]) => any): any { |
| 93 | return function ctor(this: any, ...args: any[]) { |
no test coverage detected
searching dependent graphs…