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

Function squashSegmentGroup

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

Source from the content-addressed store, hash-verified

923 * root but the `a` route lives under an empty path primary route.
924 */
925export function squashSegmentGroup(segmentGroup: UrlSegmentGroup): UrlSegmentGroup {
926 // Keyed by outlet name, which can be `__proto__`, so use a null-prototype map (see `parseParens`).
927 const newChildren: Record<string, UrlSegmentGroup> = Object.create(null);
928 for (const [childOutlet, child] of Object.entries(segmentGroup.children)) {
929 const childCandidate = squashSegmentGroup(child);
930 // moves named children in an empty path primary child into this group
931 if (
932 childOutlet === PRIMARY_OUTLET &&
933 childCandidate.segments.length === 0 &&
934 childCandidate.hasChildren()
935 ) {
936 for (const [grandChildOutlet, grandChild] of Object.entries(childCandidate.children)) {
937 setUrlDerivedKey(newChildren, grandChildOutlet, grandChild);
938 }
939 } // don't add empty children
940 else if (childCandidate.segments.length > 0 || childCandidate.hasChildren()) {
941 setUrlDerivedKey(newChildren, childOutlet, childCandidate);
942 }
943 }
944 const s = new UrlSegmentGroup(segmentGroup.segments, newChildren);
945 return mergeTrivialChildren(s);
946}
947
948/**
949 * When possible, merges the primary outlet child into the parent `UrlSegmentGroup`.

Callers 1

treeFunction · 0.90

Calls 5

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

Tested by

no test coverage detected