diff --git a/packages/compiler/src/render3/r3_template_transform.ts b/packages/compiler/src/render3/r3_template_transform.ts index 6a831f4a48..716e5254e7 100644 --- a/packages/compiler/src/render3/r3_template_transform.ts +++ b/packages/compiler/src/render3/r3_template_transform.ts @@ -458,6 +458,8 @@ class HtmlAstToIvyAst implements html.Visitor { this.reportError(`"-" is not allowed in reference names`, sourceSpan); } else if (identifier.length === 0) { this.reportError(`Reference does not have a name`, sourceSpan); + } else if (references.some(reference => reference.name === identifier)) { + this.reportError(`Reference "#${identifier}" is defined more than once`, sourceSpan); } references.push(new t.Reference(identifier, value, sourceSpan, keySpan, valueSpan)); diff --git a/packages/compiler/test/render3/r3_template_transform_spec.ts b/packages/compiler/test/render3/r3_template_transform_spec.ts index c259485073..cf1cfb40bf 100644 --- a/packages/compiler/test/render3/r3_template_transform_spec.ts +++ b/packages/compiler/test/render3/r3_template_transform_spec.ts @@ -273,6 +273,11 @@ describe('R3 template transform', () => { ]); }); + it('should report an error if a reference is used multiple times on the same template', () => { + expect(() => parse('')) + .toThrowError(/Reference "#a" is defined more than once/); + }); + it('should parse variables via let-...', () => { expectFromHtml('').toEqual([ ['Template'], @@ -463,6 +468,11 @@ describe('R3 template transform', () => { it('should report missing reference names', () => { expect(() => parse('
')).toThrowError(/Reference does not have a name/); }); + + it('should report an error if a reference is used multiple times on the same element', () => { + expect(() => parse('
')) + .toThrowError(/Reference "#a" is defined more than once/); + }); }); describe('literal attribute', () => {