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

Function setScopeOnDeclaredComponents

packages/core/src/render3/jit/module.ts:517–537  ·  view source on GitHub ↗

* Some declared components may be compiled asynchronously, and thus may not have their * ɵcmp set yet. If this is the case, then a reference to the module is written into * the `ngSelectorScope` property of the declared type.

(moduleType: Type<any>, ngModule: NgModule)

Source from the content-addressed store, hash-verified

515 * the `ngSelectorScope` property of the declared type.
516 */
517function setScopeOnDeclaredComponents(moduleType: Type<any>, ngModule: NgModule) {
518 const declarations: Type<any>[] = flatten(ngModule.declarations || EMPTY_ARRAY);
519
520 const transitiveScopes = transitiveScopesFor(moduleType);
521
522 declarations.forEach((declaration) => {
523 declaration = resolveForwardRef(declaration);
524 if (Object.hasOwn(declaration, NG_COMP_DEF)) {
525 // A `ɵcmp` field exists - go ahead and patch the component directly.
526 const component = declaration as Type<any> & {ɵcmp: ComponentDef<any>};
527 const componentDef = getComponentDef(component)!;
528 patchComponentDefWithScope(componentDef, transitiveScopes);
529 } else if (
530 !Object.hasOwn(declaration, NG_DIR_DEF) &&
531 !Object.hasOwn(declaration, NG_PIPE_DEF)
532 ) {
533 // Set `ngSelectorScope` for future reference when the component compilation finishes.
534 (declaration as Type<any> & {ngSelectorScope?: any}).ngSelectorScope = moduleType;
535 }
536 });
537}
538
539/**
540 * Patch the definition of a component with directives and pipes from the compilation scope of

Calls 6

flattenFunction · 0.90
resolveForwardRefFunction · 0.90
getComponentDefFunction · 0.90
transitiveScopesForFunction · 0.85
forEachMethod · 0.45

Tested by

no test coverage detected