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

Function squashSegmentGroup

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

Source from the content-addressed store, hash-verified

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