fix(ivy): template inputs/outputs should not be bound in template scope (#30669)
The R3TargetBinder "binds" an Angular template AST, computing semantic information regarding the template and making it accessible. One of the binding passes previously had a bug, where for the following template: <div *ngIf="foo as foo"></div> which desugars to: <ng-template ngIf [ngIf]="foo" let-foo="ngIf"> <div></div> </ng-template> would have the `[ngIf]` binding processed twice - in both the scope which contains the `<ng-template>` and the scope inside the template. The bug arises because during the latter, `foo` is a variable defined by `let-foo`, and so the R3TargetBinder would incorrectly learn that `foo` inside `[ngIf]` maps to that variable. This commit fixes the bug by only processing inputs, outputs, and templateAttrs from `Template`s in the outer scope. PR Close #30669
This commit is contained in:

committed by
Matias Niemelä

parent
b4644d7bb0
commit
b61784948a
@ -372,12 +372,8 @@ class TemplateBinder extends RecursiveAstVisitor implements Visitor {
|
||||
|
||||
private ingest(template: Template|Node[]): void {
|
||||
if (template instanceof Template) {
|
||||
// For <ng-template>s, process inputs, outputs, template attributes,
|
||||
// variables, and child nodes.
|
||||
// References were processed in the scope of the containing template.
|
||||
template.inputs.forEach(this.visitNode);
|
||||
template.outputs.forEach(this.visitNode);
|
||||
template.templateAttrs.forEach(this.visitNode);
|
||||
// For <ng-template>s, process only variables and child nodes. Inputs, outputs, templateAttrs,
|
||||
// and references were all processed in the scope of the containing template.
|
||||
template.variables.forEach(this.visitNode);
|
||||
template.children.forEach(this.visitNode);
|
||||
|
||||
|
Reference in New Issue
Block a user