MCPcopy
hub / github.com/angular/angular / squashSegmentGroup

Function squashSegmentGroup

packages/router/src/url_tree.ts:840–860  ·  view source on GitHub ↗
(segmentGroup: UrlSegmentGroup)

Source from the content-addressed store, hash-verified

838 * root but the `a` route lives under an empty path primary route.
839 */
840export function squashSegmentGroup(segmentGroup: UrlSegmentGroup): UrlSegmentGroup {
841 const newChildren: Record<string, UrlSegmentGroup> = {};
842 for (const [childOutlet, child] of Object.entries(segmentGroup.children)) {
843 const childCandidate = squashSegmentGroup(child);
844 // moves named children in an empty path primary child into this group
845 if (
846 childOutlet === PRIMARY_OUTLET &&
847 childCandidate.segments.length === 0 &&
848 childCandidate.hasChildren()
849 ) {
850 for (const [grandChildOutlet, grandChild] of Object.entries(childCandidate.children)) {
851 newChildren[grandChildOutlet] = grandChild;
852 }
853 } // don't add empty children
854 else if (childCandidate.segments.length > 0 || childCandidate.hasChildren()) {
855 newChildren[childOutlet] = childCandidate;
856 }
857 }
858 const s = new UrlSegmentGroup(segmentGroup.segments, newChildren);
859 return mergeTrivialChildren(s);
860}
861
862/**
863 * When possible, merges the primary outlet child into the parent `UrlSegmentGroup`.

Callers 1

treeFunction · 0.90

Calls 3

mergeTrivialChildrenFunction · 0.85
entriesMethod · 0.45
hasChildrenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…