fix(compiler): improve error message for undefined providers (#13546)
Closes #10835
This commit is contained in:
parent
2c0c86e3ce
commit
6b02b80a03
|
@ -862,11 +862,14 @@ export class CompileMetadataResolver {
|
|||
} else {
|
||||
provider = resolveForwardRef(provider);
|
||||
let providerMeta: cpl.ProviderMeta;
|
||||
if (provider && typeof provider == 'object' && provider.hasOwnProperty('provide')) {
|
||||
if (provider && typeof provider === 'object' && provider.hasOwnProperty('provide')) {
|
||||
this._validateProvider(provider);
|
||||
providerMeta = new cpl.ProviderMeta(provider.provide, provider);
|
||||
} else if (isValidType(provider)) {
|
||||
providerMeta = new cpl.ProviderMeta(provider, {useClass: provider});
|
||||
} else if (provider === void 0) {
|
||||
this._reportError(new SyntaxError(
|
||||
`Encountered undefined provider! Usually this means you have a circular dependencies (might be caused by using 'barrel' index.ts files.`));
|
||||
} else {
|
||||
const providersInfo =
|
||||
(<string[]>providers.reduce(
|
||||
|
|
|
@ -233,6 +233,16 @@ export function main() {
|
|||
SyntaxError, /Invalid provider for SimpleService. useClass cannot be undefined./);
|
||||
}));
|
||||
|
||||
it('should throw with descriptive error message when provider is undefined',
|
||||
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||
@NgModule({providers: [undefined]})
|
||||
class SomeModule {
|
||||
}
|
||||
|
||||
expect(() => resolver.loadNgModuleDirectiveAndPipeMetadata(SomeModule, true))
|
||||
.toThrowError(SyntaxError, /Encountered undefined provider!/);
|
||||
}));
|
||||
|
||||
it('should throw with descriptive error message when one of providers is not present',
|
||||
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||
@NgModule({declarations: [MyBrokenComp3]})
|
||||
|
|
Loading…
Reference in New Issue