* Finds `TreeNode`s with matching empty path route configs and merges them into `TreeNode` with * the children from each duplicate. This is necessary because different outlets can match a * single empty path route config and the results need to then be merged.
( nodes: Array<TreeNode<ActivatedRouteSnapshot>>, )
| 576 | * single empty path route config and the results need to then be merged. |
| 577 | */ |
| 578 | function mergeEmptyPathMatches( |
| 579 | nodes: Array<TreeNode<ActivatedRouteSnapshot>>, |
| 580 | ): Array<TreeNode<ActivatedRouteSnapshot>> { |
| 581 | const result: Array<TreeNode<ActivatedRouteSnapshot>> = []; |
| 582 | // The set of nodes which contain children that were merged from two duplicate empty path nodes. |
| 583 | const mergedNodes: Set<TreeNode<ActivatedRouteSnapshot>> = new Set(); |
| 584 | |
| 585 | for (const node of nodes) { |
| 586 | if (!hasEmptyPathConfig(node)) { |
| 587 | result.push(node); |
| 588 | continue; |
| 589 | } |
| 590 | |
| 591 | const duplicateEmptyPathNode = result.find( |
| 592 | (resultNode) => node.value.routeConfig === resultNode.value.routeConfig, |
| 593 | ); |
| 594 | if (duplicateEmptyPathNode !== undefined) { |
| 595 | duplicateEmptyPathNode.children.push(...node.children); |
| 596 | mergedNodes.add(duplicateEmptyPathNode); |
| 597 | } else { |
| 598 | result.push(node); |
| 599 | } |
| 600 | } |
| 601 | // For each node which has children from multiple sources, we need to recompute a new `TreeNode` |
| 602 | // by also merging those children. This is necessary when there are multiple empty path configs |
| 603 | // in a row. Put another way: whenever we combine children of two nodes, we need to also check |
| 604 | // if any of those children can be combined into a single node as well. |
| 605 | for (const mergedNode of mergedNodes) { |
| 606 | const mergedChildren = mergeEmptyPathMatches(mergedNode.children); |
| 607 | result.push(new TreeNode(mergedNode.value, mergedChildren)); |
| 608 | } |
| 609 | const merged = result.filter((n) => !mergedNodes.has(n)); |
| 610 | checkOutletNameUniqueness(merged); |
| 611 | return merged; |
| 612 | } |
| 613 | |
| 614 | function checkOutletNameUniqueness(nodes: TreeNode<ActivatedRouteSnapshot>[]): void { |
| 615 | const names: {[k: string]: ActivatedRouteSnapshot} = Object.create(null); |
no test coverage detected