(segmentGroup: UrlSegmentGroup)
| 923 | * root but the `a` route lives under an empty path primary route. |
| 924 | */ |
| 925 | export 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`. |
no test coverage detected