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

Function injectableDefOrInjectorDefFactory

packages/core/src/di/r3_injector.ts:576–601  ·  view source on GitHub ↗
(token: ProviderToken<any>)

Source from the content-addressed store, hash-verified

574}
575
576function injectableDefOrInjectorDefFactory(token: ProviderToken<any>): FactoryFn<any> {
577 // Most tokens will have an injectable def directly on them, which specifies a factory directly.
578 const injectableDef = getInjectableDef(token);
579 const factory = injectableDef !== null ? injectableDef.factory : getFactoryDef(token);
580
581 if (factory !== null) {
582 return factory;
583 }
584
585 // InjectionTokens should have an injectable def (ɵprov) and thus should be handled above.
586 // If it's missing that, it's an error.
587 if (token instanceof InjectionToken) {
588 throw new RuntimeError(
589 RuntimeErrorCode.INVALID_INJECTION_TOKEN,
590 ngDevMode && `Token ${stringify(token)} is missing a ɵprov definition.`,
591 );
592 }
593
594 // Undecorated types can sometimes be created if they have no constructor arguments.
595 if (token instanceof Function) {
596 return getUndecoratedInjectableFactory(token);
597 }
598
599 // There was no way to resolve a factory for this token.
600 throw new RuntimeError(RuntimeErrorCode.INVALID_INJECTION_TOKEN, ngDevMode && 'unreachable');
601}
602
603function getUndecoratedInjectableFactory(token: Function) {
604 // If the token has parameters then it has dependencies that we cannot resolve implicitly.

Callers 2

getMethod · 0.85
providerToFactoryFunction · 0.85

Calls 4

getInjectableDefFunction · 0.90
getFactoryDefFunction · 0.90
stringifyFunction · 0.90

Tested by

no test coverage detected