fix(compiler): improve error message when a module imports itself (#14646)
Closes #14644
This commit is contained in:
parent
f2adb2900d
commit
6bc6482765
|
@ -425,6 +425,7 @@ export class CompileMetadataResolver {
|
|||
}
|
||||
|
||||
if (importedModuleType) {
|
||||
if (this._checkSelfImport(moduleType, importedModuleType)) return;
|
||||
const importedModuleSummary = this.getNgModuleSummary(importedModuleType);
|
||||
if (!importedModuleSummary) {
|
||||
this._reportError(
|
||||
|
@ -567,6 +568,15 @@ export class CompileMetadataResolver {
|
|||
return compileMeta;
|
||||
}
|
||||
|
||||
private _checkSelfImport(moduleType: Type<any>, importedModuleType: Type<any>): boolean {
|
||||
if (moduleType === importedModuleType) {
|
||||
this._reportError(
|
||||
syntaxError(`'${stringifyType(moduleType)}' module can't import itself`), moduleType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private _getTypeDescriptor(type: Type<any>): string {
|
||||
if (this._directiveResolver.isDirective(type)) {
|
||||
return 'directive';
|
||||
|
|
|
@ -135,6 +135,15 @@ export function main() {
|
|||
.toThrowError(`Expected 'styles' to be an array of strings.`);
|
||||
}));
|
||||
|
||||
it('should throw with descriptive error message when a module imports itself',
|
||||
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||
@NgModule({imports: [SomeModule]})
|
||||
class SomeModule {
|
||||
}
|
||||
expect(() => resolver.loadNgModuleDirectiveAndPipeMetadata(SomeModule, true))
|
||||
.toThrowError(`'SomeModule' module can't import itself`);
|
||||
}));
|
||||
|
||||
it('should throw with descriptive error message when provider token can not be resolved',
|
||||
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||
@NgModule({declarations: [MyBrokenComp1]})
|
||||
|
@ -144,6 +153,7 @@ export function main() {
|
|||
expect(() => resolver.loadNgModuleDirectiveAndPipeMetadata(SomeModule, true))
|
||||
.toThrowError(`Can't resolve all parameters for MyBrokenComp1: (?).`);
|
||||
}));
|
||||
|
||||
it('should throw with descriptive error message when a directive is passed to imports',
|
||||
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||
@NgModule({imports: [ComponentWithoutModuleId]})
|
||||
|
|
Loading…
Reference in New Issue