mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(devtools): make sure we dont access position of an undefined parent
This commit is contained in:
+11
-4
@@ -119,12 +119,19 @@ export class DirectiveForestComponent {
|
||||
|
||||
populateParents(position: ElementPosition): void {
|
||||
this.parents = position.reduce((nodes: FlatNode[], index: number) => {
|
||||
let nodeId = [index];
|
||||
let nodePosition = [index];
|
||||
if (nodes.length > 0) {
|
||||
nodeId = nodes[nodes.length - 1].position.concat(index);
|
||||
nodePosition = nodes[nodes.length - 1].position.concat(index);
|
||||
}
|
||||
// It's possible selectedNode to be undefined
|
||||
// In this case, we don't want to push it to the list
|
||||
// of parent nodes. Instead, we want to report a warning.
|
||||
const selectedNode = this.dataSource.data.find(item => item.position.toString() === nodePosition.toString());
|
||||
if (selectedNode) {
|
||||
nodes.push(selectedNode);
|
||||
} else {
|
||||
console.warn('Cant find node for position', nodePosition);
|
||||
}
|
||||
const selectedNode = this.dataSource.data.find(item => item.position.toString() === nodeId.toString());
|
||||
nodes.push(selectedNode);
|
||||
return nodes;
|
||||
}, []);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user