Permalink
Browse files

fix(MetadataResolver): throw Component.moduleId is not a string

fixes #11590
  • Loading branch information...
vicb authored and alexeagle committed Sep 14, 2016
1 parent 255099a commit bd4045b6e753cc279aec861776221219030298b2
@@ -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'],

0 comments on commit bd4045b

Please sign in to comment.