Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): report a reasonable error with invalid metadata #20062

Merged
merged 1 commit into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions packages/compiler/src/metadata_resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,16 +664,18 @@ export class CompileMetadataResolver {
}

private _getTypeDescriptor(type: Type): string {
if (this.isDirective(type)) {
return 'directive';
}
if (isValidType(type)) {
if (this.isDirective(type)) {
return 'directive';
}

if (this.isPipe(type)) {
return 'pipe';
}
if (this.isPipe(type)) {
return 'pipe';
}

if (this.isNgModule(type)) {
return 'module';
if (this.isNgModule(type)) {
return 'module';
}
}

if ((type as any).provide) {
Expand Down
12 changes: 12 additions & 0 deletions packages/compiler/test/metadata_resolver_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,18 @@ export function main() {

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',
Expand Down