fix(compiler): Improve error message for missing annotations (#14724)
Currently, it says: Unexpected value 'FuzzyTimePipe in javascript/angular2/example/search/fuzzy_time.ts' declared by the module 'SearchModule in javascript/angular2/example/search/search_module.ts' The new error message also suggests: 'Please add a @Pipe/@Directive/@Component annotation.'
This commit is contained in:
parent
ff60c041f6
commit
3c15916e17
|
@ -433,7 +433,7 @@ export class CompileMetadataResolver {
|
||||||
if (!importedModuleSummary) {
|
if (!importedModuleSummary) {
|
||||||
this._reportError(
|
this._reportError(
|
||||||
syntaxError(
|
syntaxError(
|
||||||
`Unexpected ${this._getTypeDescriptor(importedType)} '${stringifyType(importedType)}' imported by the module '${stringifyType(moduleType)}'`),
|
`Unexpected ${this._getTypeDescriptor(importedType)} '${stringifyType(importedType)}' imported by the module '${stringifyType(moduleType)}'. Please add a @NgModule annotation.`),
|
||||||
moduleType);
|
moduleType);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -491,7 +491,7 @@ export class CompileMetadataResolver {
|
||||||
} else {
|
} else {
|
||||||
this._reportError(
|
this._reportError(
|
||||||
syntaxError(
|
syntaxError(
|
||||||
`Unexpected ${this._getTypeDescriptor(declaredType)} '${stringifyType(declaredType)}' declared by the module '${stringifyType(moduleType)}'`),
|
`Unexpected ${this._getTypeDescriptor(declaredType)} '${stringifyType(declaredType)}' declared by the module '${stringifyType(moduleType)}'. Please add a @Pipe/@Directive/@Component annotation.`),
|
||||||
moduleType);
|
moduleType);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ export function main() {
|
||||||
expect(
|
expect(
|
||||||
() => resolver.loadNgModuleDirectiveAndPipeMetadata(ModuleWithImportedComponent, true))
|
() => resolver.loadNgModuleDirectiveAndPipeMetadata(ModuleWithImportedComponent, true))
|
||||||
.toThrowError(
|
.toThrowError(
|
||||||
`Unexpected directive 'ComponentWithoutModuleId' imported by the module 'ModuleWithImportedComponent'`);
|
`Unexpected directive 'ComponentWithoutModuleId' imported by the module 'ModuleWithImportedComponent'. Please add a @NgModule annotation.`);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should throw with descriptive error message when a pipe is passed to imports',
|
it('should throw with descriptive error message when a pipe is passed to imports',
|
||||||
|
@ -175,7 +175,7 @@ export function main() {
|
||||||
}
|
}
|
||||||
expect(() => resolver.loadNgModuleDirectiveAndPipeMetadata(ModuleWithImportedPipe, true))
|
expect(() => resolver.loadNgModuleDirectiveAndPipeMetadata(ModuleWithImportedPipe, true))
|
||||||
.toThrowError(
|
.toThrowError(
|
||||||
`Unexpected pipe 'SomePipe' imported by the module 'ModuleWithImportedPipe'`);
|
`Unexpected pipe 'SomePipe' imported by the module 'ModuleWithImportedPipe'. Please add a @NgModule annotation.`);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should throw with descriptive error message when a module is passed to declarations',
|
it('should throw with descriptive error message when a module is passed to declarations',
|
||||||
|
@ -188,7 +188,29 @@ export function main() {
|
||||||
}
|
}
|
||||||
expect(() => resolver.loadNgModuleDirectiveAndPipeMetadata(ModuleWithDeclaredModule, true))
|
expect(() => resolver.loadNgModuleDirectiveAndPipeMetadata(ModuleWithDeclaredModule, true))
|
||||||
.toThrowError(
|
.toThrowError(
|
||||||
`Unexpected module 'SomeModule' declared by the module 'ModuleWithDeclaredModule'`);
|
`Unexpected module 'SomeModule' declared by the module 'ModuleWithDeclaredModule'. Please add a @Pipe/@Directive/@Component annotation.`);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should throw with descriptive error message when a declared pipe is missing annotation',
|
||||||
|
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||||
|
class SomePipe {}
|
||||||
|
@NgModule({declarations: [SomePipe]})
|
||||||
|
class ModuleWithDeclaredModule {
|
||||||
|
}
|
||||||
|
expect(() => resolver.loadNgModuleDirectiveAndPipeMetadata(ModuleWithDeclaredModule, true))
|
||||||
|
.toThrowError(
|
||||||
|
`Unexpected value 'SomePipe' declared by the module 'ModuleWithDeclaredModule'. Please add a @Pipe/@Directive/@Component annotation.`);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should throw with descriptive error message when an imported module is missing annotation',
|
||||||
|
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||||
|
class SomeModule {}
|
||||||
|
@NgModule({imports: [SomeModule]})
|
||||||
|
class ModuleWithImportedModule {
|
||||||
|
}
|
||||||
|
expect(() => resolver.loadNgModuleDirectiveAndPipeMetadata(ModuleWithImportedModule, true))
|
||||||
|
.toThrowError(
|
||||||
|
`Unexpected value 'SomeModule' imported by the module 'ModuleWithImportedModule'. Please add a @NgModule annotation.`);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should throw with descriptive error message when null is passed to declarations',
|
it('should throw with descriptive error message when null is passed to declarations',
|
||||||
|
|
|
@ -1279,7 +1279,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||||
|
|
||||||
expect(() => TestBed.createComponent(MyComp))
|
expect(() => TestBed.createComponent(MyComp))
|
||||||
.toThrowError(
|
.toThrowError(
|
||||||
`Unexpected value '${stringify(SomeDirectiveMissingAnnotation)}' declared by the module 'DynamicTestModule'`);
|
`Unexpected value '${stringify(SomeDirectiveMissingAnnotation)}' declared by the module 'DynamicTestModule'. Please add a @Pipe/@Directive/@Component annotation.`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should report a meaningful error when a component is missing view annotation', () => {
|
it('should report a meaningful error when a component is missing view annotation', () => {
|
||||||
|
|
Loading…
Reference in New Issue