(type: any, name: string)
| 437 | } |
| 438 | |
| 439 | function 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 |
no test coverage detected