diff --git a/packages/compiler-cli/src/ngtsc/indexer/src/template.ts b/packages/compiler-cli/src/ngtsc/indexer/src/template.ts index 3d932ab5353..a49fe6f2be0 100644 --- a/packages/compiler-cli/src/ngtsc/indexer/src/template.ts +++ b/packages/compiler-cli/src/ngtsc/indexer/src/template.ts @@ -232,17 +232,16 @@ class TemplateVisitor extends TmplAstRecursiveVisitor { name = node.tagName; kind = IdentifierKind.Template; } else { - // 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; - } + name = node.name; kind = IdentifierKind.Element; } + // 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 (name.startsWith(':')) { + name = name.split(':').pop()!; + } + const sourceSpan = node.startSourceSpan; // An element's or template's source span can be of the form ``, ``, or // ``. Only the selector is interesting to the indexer, so the source is 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 97c63a6d759..eb05a494e9b 100644 --- a/packages/compiler-cli/src/ngtsc/indexer/test/template_spec.ts +++ b/packages/compiler-cli/src/ngtsc/indexer/test/template_spec.ts @@ -35,6 +35,20 @@ runInEachFileSystem(() => { }); }); + it('should handle svg elements on templates', () => { + const template = ''; + const refs = getTemplateIdentifiers(bind(template)); + + const [ref] = Array.from(refs); + expect(ref).toEqual({ + kind: IdentifierKind.Template, + 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));