MCPcopy Create free account
hub / github.com/angular/angular / setClassMetadata

Function setClassMetadata

packages/core/src/render3/metadata.ts:78–112  ·  view source on GitHub ↗
(
  type: any,
  decorators: readonly any[] | null,
  ctorParameters: (() => any[]) | null,
  propDecorators: {[field: string]: any} | null,
)

Source from the content-addressed store, hash-verified

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

Callers 8

metadata_spec.tsFile · 0.90
directive_spec.tsFile · 0.90
getAOTCompiledComponentFunction · 0.85
test_bed_spec.tsFile · 0.85
createComponentFunction · 0.85
createNgModuleFunction · 0.85

Calls 2

noSideEffectsFunction · 0.90
pushMethod · 0.45

Tested by

no test coverage detected