Skip to content

Commit 859ebdd

Browse files
ayazhafizAndrewKushnir
authored andcommitted
fix(ivy): correctly bind targetToIdentifier to the TemplateVisitor (angular#31861)
`TemplateVisitor#visitBoundAttribute` currently has to invoke visiting expressions manually (this is fixed in angular#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 angular#31861
1 parent 3067309 commit 859ebdd

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class TemplateVisitor extends TmplAstRecursiveVisitor {
201201

202202
const identifiers = ExpressionVisitor.getIdentifiers(
203203
attribute.value, expressionSrc, expressionAbsolutePosition, this.boundTemplate,
204-
this.targetToIdentifier);
204+
this.targetToIdentifier.bind(this));
205205
identifiers.forEach(id => this.identifiers.add(id));
206206
}
207207
visitBoundEvent(attribute: TmplAstBoundEvent) { this.visitExpression(attribute.handler); }

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,32 @@ runInEachFileSystem(() => {
124124
});
125125
});
126126

127+
it('should discover variables in bound attributes', () => {
128+
const template = '<div #div [value]="div.innerText"></div>';
129+
const refs = getTemplateIdentifiers(bind(template));
130+
const elementReference: ElementIdentifier = {
131+
name: 'div',
132+
kind: IdentifierKind.Element,
133+
span: new AbsoluteSourceSpan(1, 4),
134+
attributes: new Set(),
135+
usedDirectives: new Set(),
136+
};
137+
const reference: ReferenceIdentifier = {
138+
name: 'div',
139+
kind: IdentifierKind.Reference,
140+
span: new AbsoluteSourceSpan(6, 9),
141+
target: {node: elementReference, directive: null},
142+
};
143+
144+
const refArr = Array.from(refs);
145+
expect(refArr).toContain({
146+
name: 'div',
147+
kind: IdentifierKind.Property,
148+
span: new AbsoluteSourceSpan(19, 22),
149+
target: reference,
150+
});
151+
});
152+
127153
it('should discover properties in template expressions', () => {
128154
const template = '<div [bar]="bar ? bar1 : bar2"></div>';
129155
const refs = getTemplateIdentifiers(bind(template));

0 commit comments

Comments
 (0)