(type: any, name: string)
| 422 | } |
| 423 | |
| 424 | function getAnnotation<T>(type: any, name: string): T | null { |
| 425 | let annotation: T | null = null; |
| 426 | collect(type.__annotations__); |
| 427 | collect(type.decorators); |
| 428 | return annotation; |
| 429 | |
| 430 | function collect(annotations: any[] | null) { |
| 431 | if (annotations) { |
| 432 | annotations.forEach(readAnnotation); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | function readAnnotation(decorator: { |
| 437 | type: {prototype: {ngMetadataName: string}; args: any[]}; |
| 438 | args: any; |
| 439 | }): void { |
| 440 | if (!annotation) { |
| 441 | const proto = Object.getPrototypeOf(decorator); |
| 442 | if (proto.ngMetadataName == name) { |
| 443 | annotation = decorator as any; |
| 444 | } else if (decorator.type) { |
| 445 | const proto = Object.getPrototypeOf(decorator.type); |
| 446 | if (proto.ngMetadataName == name) { |
| 447 | annotation = decorator.args[0]; |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | /** |
| 455 | * Keep track of compiled components. This is needed because in tests we often want to compile the |
no test coverage detected
searching dependent graphs…