(
type: any,
decorators: any[] | null,
ctorParameters: (() => any[]) | null,
propDecorators: {[field: string]: any} | null,
)
| 85 | * being tree-shaken away during production builds. |
| 86 | */ |
| 87 | export function setClassMetadata( |
| 88 | type: any, |
| 89 | decorators: any[] | null, |
| 90 | ctorParameters: (() => any[]) | null, |
| 91 | propDecorators: {[field: string]: any} | null, |
| 92 | ): void { |
| 93 | return noSideEffects(() => { |
| 94 | const clazz = type as TypeWithMetadata; |
| 95 | |
| 96 | if (decorators !== null) { |
| 97 | if (clazz.hasOwnProperty('decorators') && clazz.decorators !== undefined) { |
| 98 | clazz.decorators.push(...decorators); |
| 99 | } else { |
| 100 | clazz.decorators = decorators; |
| 101 | } |
| 102 | } |
| 103 | if (ctorParameters !== null) { |
| 104 | // Rather than merging, clobber the existing parameters. If other projects exist which |
| 105 | // use tsickle-style annotations and reflect over them in the same way, this could |
| 106 | // cause issues, but that is vanishingly unlikely. |
| 107 | clazz.ctorParameters = ctorParameters; |
| 108 | } |
| 109 | if (propDecorators !== null) { |
| 110 | // The property decorator objects are merged as it is possible different fields have |
| 111 | // different decorator types. Decorators on individual fields are not merged, as it's |
| 112 | // also incredibly unlikely that a field will be decorated both with an Angular |
| 113 | // decorator and a non-Angular decorator that's also been downleveled. |
| 114 | if (clazz.hasOwnProperty('propDecorators') && clazz.propDecorators !== undefined) { |
| 115 | clazz.propDecorators = {...clazz.propDecorators, ...propDecorators}; |
| 116 | } else { |
| 117 | clazz.propDecorators = propDecorators; |
| 118 | } |
| 119 | } |
| 120 | }) as never; |
| 121 | } |
no test coverage detected
searching dependent graphs…