( checkForStandaloneCmp: boolean, ...sources: (ImportProvidersSource | AbstractType<unknown>)[] )
| 149 | } |
| 150 | |
| 151 | export 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 |
no test coverage detected
searching dependent graphs…