MCPcopy
hub / github.com/angular/angular / makePropDecorator

Function makePropDecorator

packages/core/src/util/decorators.ts:149–199  ·  view source on GitHub ↗
(
  name: string,
  props?: (...args: any[]) => any,
  parentClass?: any,
  additionalProcessing?: (target: any, name: string, ...args: any[]) => void,
)

Source from the content-addressed store, hash-verified

147}
148
149export 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}

Callers 3

decorators_spec.tsFile · 0.90
di.tsFile · 0.90
directives.tsFile · 0.90

Calls 3

noSideEffectsFunction · 0.90
makeMetadataCtorFunction · 0.85
createMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…