Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(MetadataResolver): throw Component.moduleId is not a string
  • Loading branch information
vicb committed Sep 14, 2016
1 parent 44a4767 commit 9d79e3f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
12 changes: 9 additions & 3 deletions modules/@angular/compiler/src/metadata_resolver.ts
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions modules/@angular/compiler/test/metadata_resolver_spec.ts
Expand Up @@ -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))
Expand Down Expand Up @@ -179,6 +190,10 @@ export function main() {
class ComponentWithoutModuleId {
}

@Component({selector: 'someComponent', template: '', moduleId: <any>0})
class ComponentWithInvalidModuleId {
}

@Component({
selector: 'someSelector',
inputs: ['someProp'],
Expand Down

0 comments on commit 9d79e3f

Please sign in to comment.