diff --git a/packages/compiler-cli/src/ngtsc/indexer/src/template.ts b/packages/compiler-cli/src/ngtsc/indexer/src/template.ts index a3b1d78a4d52a..3d932ab535372 100644 --- a/packages/compiler-cli/src/ngtsc/indexer/src/template.ts +++ b/packages/compiler-cli/src/ngtsc/indexer/src/template.ts @@ -232,7 +232,15 @@ class TemplateVisitor extends TmplAstRecursiveVisitor { name = node.tagName; kind = IdentifierKind.Template; } else { - name = node.name; + // Namespaced elements have a particular format for `node.name` that needs to be handled. + // For example, an `` element has a `node.name` of `':svg:svg'`. + + // TODO(alxhub): properly handle namespaced elements + if (node.name.startsWith(':')) { + name = node.name.split(':').pop()!; + } else { + name = node.name; + } kind = IdentifierKind.Element; } const sourceSpan = node.startSourceSpan; diff --git a/packages/compiler-cli/src/ngtsc/indexer/test/template_spec.ts b/packages/compiler-cli/src/ngtsc/indexer/test/template_spec.ts index 574385e6fc6a1..97c63a6d759e6 100644 --- a/packages/compiler-cli/src/ngtsc/indexer/test/template_spec.ts +++ b/packages/compiler-cli/src/ngtsc/indexer/test/template_spec.ts @@ -21,6 +21,20 @@ function bind(template: string) { runInEachFileSystem(() => { describe('getTemplateIdentifiers', () => { + it('should handle svg elements', () => { + const template = ''; + const refs = getTemplateIdentifiers(bind(template)); + + const [ref] = Array.from(refs); + expect(ref).toEqual({ + kind: IdentifierKind.Element, + name: 'svg', + span: new AbsoluteSourceSpan(1, 4), + usedDirectives: new Set(), + attributes: new Set(), + }); + }); + it('should handle comments in interpolations', () => { const template = '{{foo // comment}}'; const refs = getTemplateIdentifiers(bind(template));