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:
Kristiyan Kostadinov 2019-01-12 13:59:11 +01:00 committed by Andrew Kushnir
parent fa53150692
commit b6510a320b
2 changed files with 16 additions and 14 deletions

View File

@ -299,11 +299,15 @@ export function discoverLocalRefs(lView: LView, nodeIndex: number): {[key: strin
const tNode = lView[TVIEW].data[nodeIndex] as TNode;
if (tNode && tNode.localNames) {
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 directiveIndex = tNode.localNames[i + 1] as number;
result[localRefName] =
directiveIndex === -1 ? getNativeByTNode(tNode, lView) ! : lView[directiveIndex];
if (directiveIndex === -1) {
result[localRefName] = lView[localIndex] || getNativeByTNode(tNode, lView);
} else {
result[localRefName] = lView[directiveIndex];
}
}
return result;
}

View File

@ -541,9 +541,7 @@ function declareTests(config?: {useJit: boolean}) {
expect(value.tagName.toLowerCase()).toEqual('div');
});
fixmeIvy(
'FW-870: DebugNode.references gets comment node instead of TemplateRef for template nodes')
.it('should assign the TemplateRef to a user-defined variable', () => {
it('should assign the TemplateRef to a user-defined variable', () => {
const fixture =
TestBed.configureTestingModule({declarations: [MyComp]})
.overrideComponent(