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

Function getAnnotation

packages/core/src/render3/jit/module.ts:439–467  ·  view source on GitHub ↗
(type: any, name: string)

Source from the content-addressed store, hash-verified

437}
438
439function getAnnotation<T>(type: any, name: string): T | null {
440 let annotation: T | null = null;
441 collect(type.__annotations__);
442 collect(type.decorators);
443 return annotation;
444
445 function collect(annotations: any[] | null) {
446 if (annotations) {
447 annotations.forEach(readAnnotation);
448 }
449 }
450
451 function readAnnotation(decorator: {
452 type: {prototype: {ngMetadataName: string}; args: any[]};
453 args: any;
454 }): void {
455 if (!annotation) {
456 const proto = Object.getPrototypeOf(decorator);
457 if (proto.ngMetadataName == name) {
458 annotation = decorator as any;
459 } else if (decorator.type) {
460 const proto = Object.getPrototypeOf(decorator.type);
461 if (proto.ngMetadataName == name) {
462 annotation = decorator.args[0];
463 }
464 }
465 }
466 }
467}
468
469/**
470 * Keep track of compiled components. This is needed because in tests we often want to compile the

Callers 1

Calls 1

collectFunction · 0.85

Tested by

no test coverage detected