(segment: UrlSegmentGroup, root: boolean)
| 522 | } |
| 523 | |
| 524 | function serializeSegment(segment: UrlSegmentGroup, root: boolean): string { |
| 525 | if (!segment.hasChildren()) { |
| 526 | return serializePaths(segment); |
| 527 | } |
| 528 | |
| 529 | if (root) { |
| 530 | const primary = segment.children[PRIMARY_OUTLET] |
| 531 | ? serializeSegment(segment.children[PRIMARY_OUTLET], false) |
| 532 | : ''; |
| 533 | const children: string[] = []; |
| 534 | |
| 535 | Object.entries(segment.children).forEach(([k, v]) => { |
| 536 | if (k !== PRIMARY_OUTLET) { |
| 537 | children.push(`${k}:${serializeSegment(v, false)}`); |
| 538 | } |
| 539 | }); |
| 540 | |
| 541 | return children.length > 0 ? `${primary}(${children.join('//')})` : primary; |
| 542 | } else { |
| 543 | // use no parenthesis if the only child is a primary outlet route |
| 544 | if (Object.keys(segment.children).length === 1 && segment.children[PRIMARY_OUTLET] != null) { |
| 545 | return `${serializePaths(segment)}/${serializeSegment(segment.children[PRIMARY_OUTLET], false)}`; |
| 546 | } |
| 547 | |
| 548 | const children = mapChildrenIntoArray(segment, (v: UrlSegmentGroup, k: string) => { |
| 549 | if (k === PRIMARY_OUTLET) { |
| 550 | return [escapeOutletDelimiter(serializeSegment(segment.children[PRIMARY_OUTLET], false))]; |
| 551 | } |
| 552 | |
| 553 | return [`${k}:${serializeSegment(v, false)}`]; |
| 554 | }); |
| 555 | |
| 556 | return `${serializePaths(segment)}/(${children.join('//')})`; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * Inside a parenthesized group, the parser distinguishes a named outlet (`name:path`) from the |
no test coverage detected