Skip to content

Commit 7316e72

Browse files
atscottAndrewKushnir
authored andcommitted
fix(compiler-cli): properly index <svg> elements when on a template (#44785)
The original fix for svg elements in 92b23f4 did not account for svg elements when they also had a structural directive on them, making the node a template. This resulted in the logic added in fix above not being applied. PR Close #44785
1 parent ac2f262 commit 7316e72

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

packages/compiler-cli/src/ngtsc/indexer/src/template.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,16 @@ class TemplateVisitor extends TmplAstRecursiveVisitor {
232232
name = node.tagName;
233233
kind = IdentifierKind.Template;
234234
} else {
235-
// Namespaced elements have a particular format for `node.name` that needs to be handled.
236-
// For example, an `<svg>` element has a `node.name` of `':svg:svg'`.
237-
238-
// TODO(alxhub): properly handle namespaced elements
239-
if (node.name.startsWith(':')) {
240-
name = node.name.split(':').pop()!;
241-
} else {
242-
name = node.name;
243-
}
235+
name = node.name;
244236
kind = IdentifierKind.Element;
245237
}
238+
// Namespaced elements have a particular format for `node.name` that needs to be handled.
239+
// For example, an `<svg>` element has a `node.name` of `':svg:svg'`.
240+
// TODO(alxhub): properly handle namespaced elements
241+
if (name.startsWith(':')) {
242+
name = name.split(':').pop()!;
243+
}
244+
246245
const sourceSpan = node.startSourceSpan;
247246
// An element's or template's source span can be of the form `<element>`, `<element />`, or
248247
// `<element></element>`. Only the selector is interesting to the indexer, so the source is

packages/compiler-cli/src/ngtsc/indexer/test/template_spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ runInEachFileSystem(() => {
3535
});
3636
});
3737

38+
it('should handle svg elements on templates', () => {
39+
const template = '<svg *ngIf="true"></svg>';
40+
const refs = getTemplateIdentifiers(bind(template));
41+
42+
const [ref] = Array.from(refs);
43+
expect(ref).toEqual({
44+
kind: IdentifierKind.Template,
45+
name: 'svg',
46+
span: new AbsoluteSourceSpan(1, 4),
47+
usedDirectives: new Set(),
48+
attributes: new Set(),
49+
});
50+
});
51+
3852
it('should handle comments in interpolations', () => {
3953
const template = '{{foo // comment}}';
4054
const refs = getTemplateIdentifiers(bind(template));

0 commit comments

Comments
 (0)