fix(ivy): correctly bind `targetToIdentifier` to the TemplateVisitor (#31861)
`TemplateVisitor#visitBoundAttribute` currently has to invoke visiting expressions manually (this is fixed in #31813). Previously, it did not bind `targetToIdentifier` to the visitor before deferring to the expression visitor, which breaks the `targetToIdentifier` code. This fixes that and adds a test to ensure the closure processed correctly. This change is urgent; without it, many indexing targets in g3 are broken. PR Close #31861
This commit is contained in:
parent
30673090ec
commit
859ebdd836
|
@ -201,7 +201,7 @@ class TemplateVisitor extends TmplAstRecursiveVisitor {
|
|||
|
||||
const identifiers = ExpressionVisitor.getIdentifiers(
|
||||
attribute.value, expressionSrc, expressionAbsolutePosition, this.boundTemplate,
|
||||
this.targetToIdentifier);
|
||||
this.targetToIdentifier.bind(this));
|
||||
identifiers.forEach(id => this.identifiers.add(id));
|
||||
}
|
||||
visitBoundEvent(attribute: TmplAstBoundEvent) { this.visitExpression(attribute.handler); }
|
||||
|
|
|
@ -124,6 +124,32 @@ runInEachFileSystem(() => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should discover variables in bound attributes', () => {
|
||||
const template = '<div #div [value]="div.innerText"></div>';
|
||||
const refs = getTemplateIdentifiers(bind(template));
|
||||
const elementReference: ElementIdentifier = {
|
||||
name: 'div',
|
||||
kind: IdentifierKind.Element,
|
||||
span: new AbsoluteSourceSpan(1, 4),
|
||||
attributes: new Set(),
|
||||
usedDirectives: new Set(),
|
||||
};
|
||||
const reference: ReferenceIdentifier = {
|
||||
name: 'div',
|
||||
kind: IdentifierKind.Reference,
|
||||
span: new AbsoluteSourceSpan(6, 9),
|
||||
target: {node: elementReference, directive: null},
|
||||
};
|
||||
|
||||
const refArr = Array.from(refs);
|
||||
expect(refArr).toContain({
|
||||
name: 'div',
|
||||
kind: IdentifierKind.Property,
|
||||
span: new AbsoluteSourceSpan(19, 22),
|
||||
target: reference,
|
||||
});
|
||||
});
|
||||
|
||||
it('should discover properties in template expressions', () => {
|
||||
const template = '<div [bar]="bar ? bar1 : bar2"></div>';
|
||||
const refs = getTemplateIdentifiers(bind(template));
|
||||
|
|
Loading…
Reference in New Issue