( name: string, props?: (...args: any[]) => any, parentClass?: any, )
| 101 | } |
| 102 | |
| 103 | export function makeParamDecorator( |
| 104 | name: string, |
| 105 | props?: (...args: any[]) => any, |
| 106 | parentClass?: any, |
| 107 | ): any { |
| 108 | return noSideEffects(() => { |
| 109 | const metaCtor = makeMetadataCtor(props); |
| 110 | function ParamDecoratorFactory( |
| 111 | this: unknown | typeof ParamDecoratorFactory, |
| 112 | ...args: any[] |
| 113 | ): any { |
| 114 | if (this instanceof ParamDecoratorFactory) { |
| 115 | metaCtor.apply(this, args); |
| 116 | return this; |
| 117 | } |
| 118 | const annotationInstance = new (<any>ParamDecoratorFactory)(...args); |
| 119 | |
| 120 | (<any>ParamDecorator).annotation = annotationInstance; |
| 121 | return ParamDecorator; |
| 122 | |
| 123 | function ParamDecorator(cls: any, unusedKey: any, index: number): any { |
| 124 | // Use of Object.defineProperty is important since it creates non-enumerable property which |
| 125 | // prevents the property is copied during subclassing. |
| 126 | const parameters = cls.hasOwnProperty(PARAMETERS) |
| 127 | ? (cls as any)[PARAMETERS] |
| 128 | : Object.defineProperty(cls, PARAMETERS, {value: []})[PARAMETERS]; |
| 129 | |
| 130 | // there might be gaps if some in between parameters do not have annotations. |
| 131 | // we pad with nulls. |
| 132 | while (parameters.length <= index) { |
| 133 | parameters.push(null); |
| 134 | } |
| 135 | |
| 136 | (parameters[index] = parameters[index] || []).push(annotationInstance); |
| 137 | return cls; |
| 138 | } |
| 139 | } |
| 140 | if (parentClass) { |
| 141 | ParamDecoratorFactory.prototype = Object.create(parentClass.prototype); |
| 142 | } |
| 143 | ParamDecoratorFactory.prototype.ngMetadataName = name; |
| 144 | (<any>ParamDecoratorFactory).annotationCls = ParamDecoratorFactory; |
| 145 | return ParamDecoratorFactory; |
| 146 | }); |
| 147 | } |
| 148 | |
| 149 | export function makePropDecorator( |
| 150 | name: string, |
no test coverage detected
searching dependent graphs…