(moduleType: Type<T>)
| 604 | * @param moduleType module that transitive scope should be calculated for. |
| 605 | */ |
| 606 | export function transitiveScopesForNgModule<T>(moduleType: Type<T>): NgModuleTransitiveScopes { |
| 607 | const def = getNgModuleDefOrThrow(moduleType); |
| 608 | |
| 609 | if (def.transitiveCompileScopes !== null) { |
| 610 | return def.transitiveCompileScopes; |
| 611 | } |
| 612 | |
| 613 | const scopes: NgModuleTransitiveScopes = { |
| 614 | schemas: def.schemas || null, |
| 615 | compilation: { |
| 616 | directives: new Set<any>(), |
| 617 | pipes: new Set<any>(), |
| 618 | }, |
| 619 | exported: { |
| 620 | directives: new Set<any>(), |
| 621 | pipes: new Set<any>(), |
| 622 | }, |
| 623 | }; |
| 624 | |
| 625 | maybeUnwrapFn(def.imports).forEach(<I>(imported: Type<I>) => { |
| 626 | // When this module imports another, the imported module's exported directives and pipes are |
| 627 | // added to the compilation scope of this module. |
| 628 | const importedScope = transitiveScopesFor(imported); |
| 629 | importedScope.exported.directives.forEach((entry) => scopes.compilation.directives.add(entry)); |
| 630 | importedScope.exported.pipes.forEach((entry) => scopes.compilation.pipes.add(entry)); |
| 631 | }); |
| 632 | |
| 633 | maybeUnwrapFn(def.declarations).forEach((declared) => { |
| 634 | const declaredWithDefs = declared as Type<any> & { |
| 635 | ɵpipe?: any; |
| 636 | }; |
| 637 | |
| 638 | if (getPipeDef(declaredWithDefs)) { |
| 639 | scopes.compilation.pipes.add(declared); |
| 640 | } else { |
| 641 | // Either declared has a ɵcmp or ɵdir, or it's a component which hasn't |
| 642 | // had its template compiled yet. In either case, it gets added to the compilation's |
| 643 | // directives. |
| 644 | scopes.compilation.directives.add(declared); |
| 645 | } |
| 646 | }); |
| 647 | |
| 648 | maybeUnwrapFn(def.exports).forEach(<E>(exported: Type<E>) => { |
| 649 | const exportedType = exported as Type<E> & { |
| 650 | // Components, Directives, NgModules, and Pipes can all be exported. |
| 651 | ɵcmp?: any; |
| 652 | ɵdir?: any; |
| 653 | ɵmod?: NgModuleDef<E>; |
| 654 | ɵpipe?: any; |
| 655 | }; |
| 656 | |
| 657 | // Either the type is a module, a pipe, or a component/directive (which may not have a |
| 658 | // ɵcmp as it might be compiled asynchronously). |
| 659 | if (isNgModule(exportedType)) { |
| 660 | // When this module exports another, the exported module's exported directives and pipes are |
| 661 | // added to both the compilation and exported scopes of this module. |
| 662 | const exportedScope = transitiveScopesFor(exportedType); |
| 663 | exportedScope.exported.directives.forEach((entry) => { |
nothing calls this directly
no test coverage detected
searching dependent graphs…