fix(ivy): properly tree-shake away StaticInjector (#30219)
Ivy uses R3Injector, but we are currently pulling in both the StaticInjector (View Engine injector) and the R3Injector when running with Ivy. This commit adds an ivy switch so calling Injector.create() pulls in the correct implementation of the injector depending on whether you are using VE or Ivy. This saves us about 3KB in the bundle. PR Close #30219
This commit is contained in:
@ -6,8 +6,12 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {InjectorType} from '../di/interface/defs';
|
||||
import {stringify} from '../util/stringify';
|
||||
|
||||
import {TNode} from './interfaces/node';
|
||||
|
||||
|
||||
/** Called when directives inject each other (creating a circular dependency) */
|
||||
export function throwCyclicDependencyError(token: any): never {
|
||||
throw new Error(`Cannot instantiate cyclic dependency! ${token}`);
|
||||
@ -31,3 +35,20 @@ export function throwErrorIfNoChangesMode(
|
||||
// TODO: include debug context
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
||||
export function throwMixedMultiProviderError() {
|
||||
throw new Error(`Cannot mix multi providers and regular providers`);
|
||||
}
|
||||
|
||||
export function throwInvalidProviderError(
|
||||
ngModuleType?: InjectorType<any>, providers?: any[], provider?: any) {
|
||||
let ngModuleDetail = '';
|
||||
if (ngModuleType && providers) {
|
||||
const providerDetail = providers.map(v => v == provider ? '?' + provider + '?' : '...');
|
||||
ngModuleDetail =
|
||||
` - only instances of Provider and Type are allowed, got: [${providerDetail.join(', ')}]`;
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Invalid provider for the NgModule '${stringify(ngModuleType)}'` + ngModuleDetail);
|
||||
}
|
||||
|
Reference in New Issue
Block a user