MCPcopy Create free account
hub / github.com/angular/angular / squashSegmentGroup

Function squashSegmentGroup

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

Source from the content-addressed store, hash-verified

849 * root but the `a` route lives under an empty path primary route.
850 */
851export function squashSegmentGroup(segmentGroup: UrlSegmentGroup): UrlSegmentGroup {
852 // Keyed by outlet name, which can be `__proto__`, so use a null-prototype map (see `parseParens`).
853 const newChildren: Record<string, UrlSegmentGroup> = Object.create(null);
854 for (const [childOutlet, child] of Object.entries(segmentGroup.children)) {
855 const childCandidate = squashSegmentGroup(child);
856 // moves named children in an empty path primary child into this group
857 if (
858 childOutlet === PRIMARY_OUTLET &&
859 childCandidate.segments.length === 0 &&
860 childCandidate.hasChildren()
861 ) {
862 for (const [grandChildOutlet, grandChild] of Object.entries(childCandidate.children)) {
863 newChildren[grandChildOutlet] = grandChild;
864 }
865 } // don't add empty children
866 else if (childCandidate.segments.length > 0 || childCandidate.hasChildren()) {
867 newChildren[childOutlet] = childCandidate;
868 }
869 }
870 const s = new UrlSegmentGroup(segmentGroup.segments, newChildren);
871 return mergeTrivialChildren(s);
872}
873
874/**
875 * When possible, merges the primary outlet child into the parent `UrlSegmentGroup`.

Callers 1

treeFunction · 0.90

Calls 4

mergeTrivialChildrenFunction · 0.85
createMethod · 0.65
entriesMethod · 0.45
hasChildrenMethod · 0.45

Tested by

no test coverage detected