MCPcopy Index your code
hub / github.com/angular/angular / internalImportProvidersFrom

Function internalImportProvidersFrom

packages/core/src/di/provider_collection.ts:151–189  ·  view source on GitHub ↗
(
  checkForStandaloneCmp: boolean,
  ...sources: (ImportProvidersSource | AbstractType<unknown>)[]
)

Source from the content-addressed store, hash-verified

149}
150
151export function internalImportProvidersFrom(
152 checkForStandaloneCmp: boolean,
153 ...sources: (ImportProvidersSource | AbstractType<unknown>)[]
154): Provider[] {
155 const providersOut: SingleProvider[] = [];
156 const dedup = new Set<Type<unknown> | AbstractType<unknown>>(); // already seen types
157 let injectorTypesWithProviders: InjectorTypeWithProviders<unknown>[] | undefined;
158
159 const collectProviders: WalkProviderTreeVisitor = (provider) => {
160 providersOut.push(provider);
161 };
162
163 deepForEach(sources, (source) => {
164 if ((typeof ngDevMode === 'undefined' || ngDevMode) && checkForStandaloneCmp) {
165 const cmpDef = getComponentDef(source);
166 if (cmpDef?.standalone) {
167 throw new RuntimeError(
168 RuntimeErrorCode.IMPORT_PROVIDERS_FROM_STANDALONE,
169 `Importing providers supports NgModule or ModuleWithProviders but got a standalone component "${stringifyForError(
170 source,
171 )}"`,
172 );
173 }
174 }
175
176 // Narrow `source` to access the internal type analogue for `ModuleWithProviders`.
177 const internalSource = source as Type<unknown> | InjectorTypeWithProviders<unknown>;
178 if (walkProviderTree(internalSource, collectProviders, [], dedup)) {
179 injectorTypesWithProviders ||= [];
180 injectorTypesWithProviders.push(internalSource);
181 }
182 });
183 // Collect all providers from `ModuleWithProviders` types.
184 if (injectorTypesWithProviders !== undefined) {
185 processInjectorTypesWithProviders(injectorTypesWithProviders, collectProviders);
186 }
187
188 return providersOut;
189}
190
191/**
192 * Collects all providers from the list of `ModuleWithProviders` and appends them to the provided

Calls 6

deepForEachFunction · 0.90
getComponentDefFunction · 0.90
stringifyForErrorFunction · 0.90
walkProviderTreeFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…