MCPcopy
hub / github.com/angular/angular / mergeEmptyPathMatches

Function mergeEmptyPathMatches

packages/router/src/recognize.ts:552–584  ·  view source on GitHub ↗

* 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>>,
)

Source from the content-addressed store, hash-verified

550 * single empty path route config and the results need to then be merged.
551 */
552function mergeEmptyPathMatches(
553 nodes: Array<TreeNode<ActivatedRouteSnapshot>>,
554): Array<TreeNode<ActivatedRouteSnapshot>> {
555 const result: Array<TreeNode<ActivatedRouteSnapshot>> = [];
556 // The set of nodes which contain children that were merged from two duplicate empty path nodes.
557 const mergedNodes: Set<TreeNode<ActivatedRouteSnapshot>> = new Set();
558
559 for (const node of nodes) {
560 if (!hasEmptyPathConfig(node)) {
561 result.push(node);
562 continue;
563 }
564
565 const duplicateEmptyPathNode = result.find(
566 (resultNode) => node.value.routeConfig === resultNode.value.routeConfig,
567 );
568 if (duplicateEmptyPathNode !== undefined) {
569 duplicateEmptyPathNode.children.push(...node.children);
570 mergedNodes.add(duplicateEmptyPathNode);
571 } else {
572 result.push(node);
573 }
574 }
575 // For each node which has children from multiple sources, we need to recompute a new `TreeNode`
576 // by also merging those children. This is necessary when there are multiple empty path configs
577 // in a row. Put another way: whenever we combine children of two nodes, we need to also check
578 // if any of those children can be combined into a single node as well.
579 for (const mergedNode of mergedNodes) {
580 const mergedChildren = mergeEmptyPathMatches(mergedNode.children);
581 result.push(new TreeNode(mergedNode.value, mergedChildren));
582 }
583 return result.filter((n) => !mergedNodes.has(n));
584}
585
586function checkOutletNameUniqueness(nodes: TreeNode<ActivatedRouteSnapshot>[]): void {
587 const names: {[k: string]: ActivatedRouteSnapshot} = {};

Callers 1

processChildrenMethod · 0.85

Calls 6

hasEmptyPathConfigFunction · 0.85
addMethod · 0.65
hasMethod · 0.65
pushMethod · 0.45
findMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…