fix(core): improve error when multiple components match the same element

Closes #7067
This commit is contained in:
Zaven Muradyan 2016-10-28 20:59:00 -07:00 committed by vsavkin
parent a0aecac0e5
commit e9fd8645ed
2 changed files with 12 additions and 4 deletions

View File

@ -644,7 +644,11 @@ class TemplateParseVisitor implements html.Visitor {
private _assertOnlyOneComponent(directives: DirectiveAst[], sourceSpan: ParseSourceSpan) { private _assertOnlyOneComponent(directives: DirectiveAst[], sourceSpan: ParseSourceSpan) {
const componentTypeNames = this._findComponentDirectiveNames(directives); const componentTypeNames = this._findComponentDirectiveNames(directives);
if (componentTypeNames.length > 1) { if (componentTypeNames.length > 1) {
this._reportError(`More than one component: ${componentTypeNames.join(',')}`, sourceSpan); this._reportError(
`More than one component matched on this element.\n` +
`Make sure that only one component's selector can match a given element.\n` +
`Conflicting components: ${componentTypeNames.join(',')}`,
sourceSpan);
} }
} }

View File

@ -1495,8 +1495,12 @@ Parser Error: Unexpected token 'b' at column 3 in [a b] in TestComp@0:5 ("<div [
{moduleUrl: someModuleUrl, name: 'DirB', reference: {} as Type<any>}), {moduleUrl: someModuleUrl, name: 'DirB', reference: {} as Type<any>}),
template: new CompileTemplateMetadata({ngContentSelectors: []}) template: new CompileTemplateMetadata({ngContentSelectors: []})
}); });
expect(() => parse('<div>', [dirB, dirA])).toThrowError(`Template parse errors: expect(() => parse('<div>', [dirB, dirA]))
More than one component: DirB,DirA ("[ERROR ->]<div>"): TestComp@0:0`); .toThrowError(
`Template parse errors:\n` +
`More than one component matched on this element.\n` +
`Make sure that only one component's selector can match a given element.\n` +
`Conflicting components: DirB,DirA ("[ERROR ->]<div>"): TestComp@0:0`);
}); });
it('should not allow components or element bindings nor dom events on explicit embedded templates', it('should not allow components or element bindings nor dom events on explicit embedded templates',