fix(compiler): report a reasonable error with invalid metadata (#20062)
The compiler would throw an internal exception if an import using the `ngModule` syntax and the module as not a resolvable symbol. Fixes: #20049
This commit is contained in:
parent
880201681f
commit
bf22f2df88
|
@ -664,16 +664,18 @@ export class CompileMetadataResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getTypeDescriptor(type: Type): string {
|
private _getTypeDescriptor(type: Type): string {
|
||||||
if (this.isDirective(type)) {
|
if (isValidType(type)) {
|
||||||
return 'directive';
|
if (this.isDirective(type)) {
|
||||||
}
|
return 'directive';
|
||||||
|
}
|
||||||
|
|
||||||
if (this.isPipe(type)) {
|
if (this.isPipe(type)) {
|
||||||
return 'pipe';
|
return 'pipe';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isNgModule(type)) {
|
if (this.isNgModule(type)) {
|
||||||
return 'module';
|
return 'module';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((type as any).provide) {
|
if ((type as any).provide) {
|
||||||
|
|
|
@ -399,6 +399,18 @@ export function main() {
|
||||||
|
|
||||||
expect(() => resolver.getNgModuleMetadata(ModuleWithComponentInBootstrap)).not.toThrow();
|
expect(() => resolver.getNgModuleMetadata(ModuleWithComponentInBootstrap)).not.toThrow();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// #20049
|
||||||
|
it('should throw a reasonable message when an invalid import is given',
|
||||||
|
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||||
|
@NgModule({imports: [{ngModule: true as any}]})
|
||||||
|
class InvalidModule {
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(() => { resolver.getNgModuleMetadata(InvalidModule); })
|
||||||
|
.toThrowError(
|
||||||
|
`Unexpected value '[object Object]' imported by the module 'InvalidModule'. Please add a @NgModule annotation.`);
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should dedupe declarations in NgModule',
|
it('should dedupe declarations in NgModule',
|
||||||
|
|
Loading…
Reference in New Issue