MCPcopy Index your code
hub / github.com/angular/angular / makeDecorator

Function makeDecorator

packages/core/src/util/decorators.ts:47–90  ·  view source on GitHub ↗
(
  name: string,
  props?: (...args: any[]) => any,
  parentClass?: any,
  additionalProcessing?: (type: Type<T>) => void,
  typeFn?: (type: Type<T>, ...args: any[]) => void,
)

Source from the content-addressed store, hash-verified

45 * @suppress {globalThis}
46 */
47export function makeDecorator<T>(
48 name: string,
49 props?: (...args: any[]) => any,
50 parentClass?: any,
51 additionalProcessing?: (type: Type<T>) => void,
52 typeFn?: (type: Type<T>, ...args: any[]) => void,
53): {new (...args: any[]): any; (...args: any[]): any; (...args: any[]): (cls: any) => any} {
54 return noSideEffects(() => {
55 const metaCtor = makeMetadataCtor(props);
56
57 function DecoratorFactory(
58 this: unknown | typeof DecoratorFactory,
59 ...args: any[]
60 ): (cls: Type<T>) => any {
61 if (this instanceof DecoratorFactory) {
62 metaCtor.call(this, ...args);
63 return this as typeof DecoratorFactory;
64 }
65
66 const annotationInstance = new (DecoratorFactory as any)(...args);
67 return function TypeDecorator(cls: Type<T>) {
68 if (typeFn) typeFn(cls, ...args);
69 // Use of Object.defineProperty is important since it creates non-enumerable property which
70 // prevents the property is copied during subclassing.
71 const annotations = cls.hasOwnProperty(ANNOTATIONS)
72 ? (cls as any)[ANNOTATIONS]
73 : (Object.defineProperty(cls, ANNOTATIONS, {value: []}) as any)[ANNOTATIONS];
74 annotations.push(annotationInstance);
75
76 if (additionalProcessing) additionalProcessing(cls);
77
78 return cls;
79 };
80 }
81
82 if (parentClass) {
83 DecoratorFactory.prototype = Object.create(parentClass.prototype);
84 }
85
86 DecoratorFactory.prototype.ngMetadataName = name;
87 (DecoratorFactory as any).annotationCls = DecoratorFactory;
88 return DecoratorFactory as any;
89 });
90}
91
92function makeMetadataCtor(props?: (...args: any[]) => any): any {
93 return function ctor(this: any, ...args: any[]) {

Callers 5

decorators_spec.tsFile · 0.90
injectable.tsFile · 0.90
service.tsFile · 0.90
ng_module.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…