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