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

Function transitiveScopesForNgModule

packages/core/src/render3/jit/module.ts:621–695  ·  view source on GitHub ↗
(moduleType: Type<T>)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 7

getNgModuleDefOrThrowFunction · 0.90
maybeUnwrapFnFunction · 0.90
getPipeDefFunction · 0.90
isNgModuleFunction · 0.90
transitiveScopesForFunction · 0.85
addMethod · 0.65
forEachMethod · 0.45

Tested by

no test coverage detected