mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(compiler-cli): properly index <svg> elements when on a template (#44785)
The original fix for svg elements in https://github.com/angular/angular/commit/92b23f48519a1adb460a431c356bcd9917fb059d 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
This commit is contained in:
committed by
Andrew Kushnir
parent
ac2f262e9a
commit
7316e72ec5
@@ -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 `<svg>` 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 `<svg>` 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 `<element>`, `<element />`, or
|
||||
// `<element></element>`. Only the selector is interesting to the indexer, so the source is
|
||||
|
||||
@@ -35,6 +35,20 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle svg elements on templates', () => {
|
||||
const template = '<svg *ngIf="true"></svg>';
|
||||
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));
|
||||
|
||||
Reference in New Issue
Block a user