( name: string, props?: (...args: any[]) => any, parentClass?: any, additionalProcessing?: (target: any, name: string, ...args: any[]) => void, )
| 147 | } |
| 148 | |
| 149 | export function makePropDecorator( |
| 150 | name: string, |
| 151 | props?: (...args: any[]) => any, |
| 152 | parentClass?: any, |
| 153 | additionalProcessing?: (target: any, name: string, ...args: any[]) => void, |
| 154 | ): any { |
| 155 | return noSideEffects(() => { |
| 156 | const metaCtor = makeMetadataCtor(props); |
| 157 | |
| 158 | function PropDecoratorFactory( |
| 159 | this: unknown | typeof PropDecoratorFactory, |
| 160 | ...args: any[] |
| 161 | ): any { |
| 162 | if (this instanceof PropDecoratorFactory) { |
| 163 | metaCtor.apply(this, args); |
| 164 | return this; |
| 165 | } |
| 166 | |
| 167 | const decoratorInstance = new (<any>PropDecoratorFactory)(...args); |
| 168 | |
| 169 | function PropDecorator(target: any, name: string) { |
| 170 | // target is undefined with standard decorators. This case is not supported and will throw |
| 171 | // if this decorator is used in JIT mode with standard decorators. |
| 172 | if (target === undefined) { |
| 173 | throw new Error('Standard Angular field decorators are not supported in JIT mode.'); |
| 174 | } |
| 175 | |
| 176 | const constructor = target.constructor; |
| 177 | // Use of Object.defineProperty is important because it creates a non-enumerable property |
| 178 | // which prevents the property from being copied during subclassing. |
| 179 | const meta = constructor.hasOwnProperty(PROP_METADATA) |
| 180 | ? (constructor as any)[PROP_METADATA] |
| 181 | : Object.defineProperty(constructor, PROP_METADATA, {value: {}})[PROP_METADATA]; |
| 182 | meta[name] = (meta.hasOwnProperty(name) && meta[name]) || []; |
| 183 | meta[name].unshift(decoratorInstance); |
| 184 | |
| 185 | if (additionalProcessing) additionalProcessing(target, name, ...args); |
| 186 | } |
| 187 | |
| 188 | return PropDecorator; |
| 189 | } |
| 190 | |
| 191 | if (parentClass) { |
| 192 | PropDecoratorFactory.prototype = Object.create(parentClass.prototype); |
| 193 | } |
| 194 | |
| 195 | PropDecoratorFactory.prototype.ngMetadataName = name; |
| 196 | (<any>PropDecoratorFactory).annotationCls = PropDecoratorFactory; |
| 197 | return PropDecoratorFactory; |
| 198 | }); |
| 199 | } |
no test coverage detected
searching dependent graphs…