fix(ivy): debug node references not returning template ref (#28101)
Fixes the `DebugNode.references` returning a reference to the underlying comment node, rather than the `TemplateRef` that the reference is pointing to. The issue comes from the fact that `discoverLocalRefs` falls back directly to returning the native node, if the ref isn't pointing to a directive, rather than looking through the locals. These changes resolve FW-870. PR Close #28101
This commit is contained in:
parent
fa53150692
commit
b6510a320b
@ -299,11 +299,15 @@ export function discoverLocalRefs(lView: LView, nodeIndex: number): {[key: strin
|
|||||||
const tNode = lView[TVIEW].data[nodeIndex] as TNode;
|
const tNode = lView[TVIEW].data[nodeIndex] as TNode;
|
||||||
if (tNode && tNode.localNames) {
|
if (tNode && tNode.localNames) {
|
||||||
const result: {[key: string]: any} = {};
|
const result: {[key: string]: any} = {};
|
||||||
for (let i = 0; i < tNode.localNames.length; i += 2) {
|
let localIndex = tNode.index + 1;
|
||||||
|
for (let i = 0; i < tNode.localNames.length; i += 2, localIndex++) {
|
||||||
const localRefName = tNode.localNames[i];
|
const localRefName = tNode.localNames[i];
|
||||||
const directiveIndex = tNode.localNames[i + 1] as number;
|
const directiveIndex = tNode.localNames[i + 1] as number;
|
||||||
result[localRefName] =
|
if (directiveIndex === -1) {
|
||||||
directiveIndex === -1 ? getNativeByTNode(tNode, lView) ! : lView[directiveIndex];
|
result[localRefName] = lView[localIndex] || getNativeByTNode(tNode, lView);
|
||||||
|
} else {
|
||||||
|
result[localRefName] = lView[directiveIndex];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -541,9 +541,7 @@ function declareTests(config?: {useJit: boolean}) {
|
|||||||
expect(value.tagName.toLowerCase()).toEqual('div');
|
expect(value.tagName.toLowerCase()).toEqual('div');
|
||||||
});
|
});
|
||||||
|
|
||||||
fixmeIvy(
|
it('should assign the TemplateRef to a user-defined variable', () => {
|
||||||
'FW-870: DebugNode.references gets comment node instead of TemplateRef for template nodes')
|
|
||||||
.it('should assign the TemplateRef to a user-defined variable', () => {
|
|
||||||
const fixture =
|
const fixture =
|
||||||
TestBed.configureTestingModule({declarations: [MyComp]})
|
TestBed.configureTestingModule({declarations: [MyComp]})
|
||||||
.overrideComponent(
|
.overrideComponent(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user