fix(core): improve error when multiple components match the same element
Closes #7067
This commit is contained in:
parent
a0aecac0e5
commit
e9fd8645ed
|
@ -644,7 +644,11 @@ class TemplateParseVisitor implements html.Visitor {
|
|||
private _assertOnlyOneComponent(directives: DirectiveAst[], sourceSpan: ParseSourceSpan) {
|
||||
const componentTypeNames = this._findComponentDirectiveNames(directives);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -831,4 +835,4 @@ const NON_BINDABLE_VISITOR = new NonBindableVisitor();
|
|||
|
||||
function _isEmptyTextNode(node: html.Node): boolean {
|
||||
return node instanceof html.Text && node.value.trim().length == 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>}),
|
||||
template: new CompileTemplateMetadata({ngContentSelectors: []})
|
||||
});
|
||||
expect(() => parse('<div>', [dirB, dirA])).toThrowError(`Template parse errors:
|
||||
More than one component: DirB,DirA ("[ERROR ->]<div>"): TestComp@0:0`);
|
||||
expect(() => parse('<div>', [dirB, dirA]))
|
||||
.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',
|
||||
|
|
Loading…
Reference in New Issue