fix(MetadataResolver): throw Component.moduleId is not a string
fixes #11590
This commit is contained in:
parent
255099aa61
commit
bd4045b6e7
|
@ -759,15 +759,21 @@ function staticTypeModuleUrl(value: any): string {
|
|||
return cpl.isStaticSymbol(value) ? value.filePath : null;
|
||||
}
|
||||
|
||||
function componentModuleUrl(reflector: ReflectorReader, type: Type<any>, cmpMetadata: Component): string {
|
||||
function componentModuleUrl(
|
||||
reflector: ReflectorReader, type: Type<any>, cmpMetadata: Component): string {
|
||||
if (cpl.isStaticSymbol(type)) {
|
||||
return staticTypeModuleUrl(type);
|
||||
}
|
||||
|
||||
if (isPresent(cmpMetadata.moduleId)) {
|
||||
const moduleId = cmpMetadata.moduleId;
|
||||
const moduleId = cmpMetadata.moduleId;
|
||||
|
||||
if (typeof moduleId === 'string') {
|
||||
const scheme = getUrlScheme(moduleId);
|
||||
return scheme ? moduleId : `package:${moduleId}${MODULE_SUFFIX}`;
|
||||
} else if (moduleId !== null && moduleId !== void 0) {
|
||||
throw new Error(
|
||||
`moduleId should be a string in "${stringify(type)}". See https://goo.gl/wIDDiL for more information.\n` +
|
||||
`If you're using Webpack you should inline the template and the styles, see https://goo.gl/X2J8zc.`);
|
||||
}
|
||||
|
||||
return reflector.importUri(type);
|
||||
|
|
|
@ -52,6 +52,17 @@ export function main() {
|
|||
expect(value.endsWith(expectedEndValue)).toBe(true);
|
||||
}));
|
||||
|
||||
it('should throw when the moduleId is not a string',
|
||||
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||
expect(() => resolver.getDirectiveMetadata(ComponentWithInvalidModuleId))
|
||||
.toThrowError(
|
||||
`moduleId should be a string in "ComponentWithInvalidModuleId". See` +
|
||||
` https://goo.gl/wIDDiL for more information.\n` +
|
||||
`If you're using Webpack you should inline the template and the styles, see` +
|
||||
` https://goo.gl/X2J8zc.`);
|
||||
}));
|
||||
|
||||
|
||||
it('should throw when metadata is incorrectly typed',
|
||||
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||
expect(() => resolver.getDirectiveMetadata(MalformedStylesComponent))
|
||||
|
@ -179,6 +190,10 @@ export function main() {
|
|||
class ComponentWithoutModuleId {
|
||||
}
|
||||
|
||||
@Component({selector: 'someComponent', template: '', moduleId: <any>0})
|
||||
class ComponentWithInvalidModuleId {
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'someSelector',
|
||||
inputs: ['someProp'],
|
||||
|
|
Loading…
Reference in New Issue