feat(ivy): allow non-unique #localRefs to be defined in a template (#28627)
Prior to this change in Ivy we had strict check that disabled non-unique #localRefs usage within a given template. While this limitation was technically present in View Engine, in many cases View Engine neglected this restriction and as a result, some apps relied on a fact that multiple non-unique #localRefs can be defined and utilized to query elements via @ViewChild(ren) and @ContentChild(ren). In order to provide better compatibility with View Engine, this commit removes existing restriction. As a part of this commit, are few tests were added to verify VE and Ivy compatibility in most common use-cases where multiple non-unique #localRefs were used. PR Close #28627
This commit is contained in:

committed by
Miško Hevery

parent
1e64f37257
commit
a9afe629c7
@ -1395,8 +1395,14 @@ export class BindingScope implements LocalResolver {
|
||||
set(retrievalLevel: number, name: string, lhs: o.ReadVarExpr,
|
||||
priority: number = DeclarationPriority.DEFAULT,
|
||||
declareLocalCallback?: DeclareLocalVarCallback, localRef?: true): BindingScope {
|
||||
!this.map.has(name) ||
|
||||
error(`The name ${name} is already defined in scope to be ${this.map.get(name)}`);
|
||||
if (this.map.has(name)) {
|
||||
if (localRef) {
|
||||
// Do not throw an error if it's a local ref and do not update existing value,
|
||||
// so the first defined ref is always returned.
|
||||
return this;
|
||||
}
|
||||
error(`The name ${name} is already defined in scope to be ${this.map.get(name)}`);
|
||||
}
|
||||
this.map.set(name, {
|
||||
retrievalLevel: retrievalLevel,
|
||||
lhs: lhs,
|
||||
|
Reference in New Issue
Block a user