fix(compiler): error when `NgModule.bootstrap` contains `undefined` or `null`
This commit is contained in:
parent
aa9b617c9d
commit
ea95c391c1
|
@ -304,9 +304,14 @@ export class CompileMetadataResolver {
|
||||||
.map(type => this.getTypeMetadata(type, staticTypeModuleUrl(type))));
|
.map(type => this.getTypeMetadata(type, staticTypeModuleUrl(type))));
|
||||||
}
|
}
|
||||||
if (meta.bootstrap) {
|
if (meta.bootstrap) {
|
||||||
bootstrapComponents.push(
|
const typeMetadata = flattenArray(meta.bootstrap).map(type => {
|
||||||
...flattenArray(meta.bootstrap)
|
if (!isValidType(type)) {
|
||||||
.map(type => this.getTypeMetadata(type, staticTypeModuleUrl(type))));
|
throw new Error(
|
||||||
|
`Unexpected value '${stringify(type)}' used in the bootstrap property of module '${stringify(moduleType)}'`);
|
||||||
|
}
|
||||||
|
return this.getTypeMetadata(type, staticTypeModuleUrl(type));
|
||||||
|
});
|
||||||
|
bootstrapComponents.push(...typeMetadata);
|
||||||
}
|
}
|
||||||
entryComponents.push(...bootstrapComponents);
|
entryComponents.push(...bootstrapComponents);
|
||||||
if (meta.schemas) {
|
if (meta.schemas) {
|
||||||
|
|
|
@ -140,6 +140,23 @@ export function main() {
|
||||||
`Invalid viewProviders for "MyBrokenComp4" - only instances of Provider and Type are allowed, got: [?null?, ...]`);
|
`Invalid viewProviders for "MyBrokenComp4" - only instances of Provider and Type are allowed, got: [?null?, ...]`);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should throw with descriptive error message when null or undefined is passed to module bootstrap',
|
||||||
|
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||||
|
@NgModule({bootstrap: [null]})
|
||||||
|
class ModuleWithNullBootstrap {
|
||||||
|
}
|
||||||
|
@NgModule({bootstrap: [undefined]})
|
||||||
|
class ModuleWithUndefinedBootstrap {
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(() => resolver.getNgModuleMetadata(ModuleWithNullBootstrap))
|
||||||
|
.toThrowError(
|
||||||
|
`Unexpected value 'null' used in the bootstrap property of module 'ModuleWithNullBootstrap'`);
|
||||||
|
expect(() => resolver.getNgModuleMetadata(ModuleWithUndefinedBootstrap))
|
||||||
|
.toThrowError(
|
||||||
|
`Unexpected value 'undefined' used in the bootstrap property of module 'ModuleWithUndefinedBootstrap'`);
|
||||||
|
}));
|
||||||
|
|
||||||
it('should throw an error when the interpolation config has invalid symbols',
|
it('should throw an error when the interpolation config has invalid symbols',
|
||||||
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||||
expect(() => resolver.getDirectiveMetadata(ComponentWithInvalidInterpolation1))
|
expect(() => resolver.getDirectiveMetadata(ComponentWithInvalidInterpolation1))
|
||||||
|
|
Loading…
Reference in New Issue