(segmentGroup: UrlSegmentGroup)
| 838 | * root but the `a` route lives under an empty path primary route. |
| 839 | */ |
| 840 | export function squashSegmentGroup(segmentGroup: UrlSegmentGroup): UrlSegmentGroup { |
| 841 | const newChildren: Record<string, UrlSegmentGroup> = {}; |
| 842 | for (const [childOutlet, child] of Object.entries(segmentGroup.children)) { |
| 843 | const childCandidate = squashSegmentGroup(child); |
| 844 | // moves named children in an empty path primary child into this group |
| 845 | if ( |
| 846 | childOutlet === PRIMARY_OUTLET && |
| 847 | childCandidate.segments.length === 0 && |
| 848 | childCandidate.hasChildren() |
| 849 | ) { |
| 850 | for (const [grandChildOutlet, grandChild] of Object.entries(childCandidate.children)) { |
| 851 | newChildren[grandChildOutlet] = grandChild; |
| 852 | } |
| 853 | } // don't add empty children |
| 854 | else if (childCandidate.segments.length > 0 || childCandidate.hasChildren()) { |
| 855 | newChildren[childOutlet] = childCandidate; |
| 856 | } |
| 857 | } |
| 858 | const s = new UrlSegmentGroup(segmentGroup.segments, newChildren); |
| 859 | return mergeTrivialChildren(s); |
| 860 | } |
| 861 | |
| 862 | /** |
| 863 | * When possible, merges the primary outlet child into the parent `UrlSegmentGroup`. |
no test coverage detected
searching dependent graphs…