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

Method parseParens

packages/router/src/url_tree.ts:763–803  ·  view source on GitHub ↗
(allowPrimary: boolean, depth: number)

Source from the content-addressed store, hash-verified

761
762 // parse `(a/b//outlet_name:c/d)`
763 private parseParens(allowPrimary: boolean, depth: number): {[outlet: string]: UrlSegmentGroup} {
764 // The outlet name is taken verbatim from the URL, so it can be `__proto__`. Indexing a plain
765 // object with that key assigns through the inherited `__proto__` setter instead of creating an
766 // outlet, which drops the outlet and mutates the map's prototype (and throws under Node's
767 // `--disable-proto=throw`). A null-prototype map makes `__proto__` an ordinary key.
768 const segments: {[key: string]: UrlSegmentGroup} = Object.create(null);
769 this.capture('(');
770
771 while (!this.consumeOptional(')') && this.remaining.length > 0) {
772 const path = matchSegments(this.remaining);
773
774 const next = this.remaining[path.length];
775
776 // if is is not one of these characters, then the segment was unescaped
777 // or the group was not closed
778 if (next !== '/' && next !== ')' && next !== ';') {
779 throw new RuntimeError(
780 RuntimeErrorCode.UNPARSABLE_URL,
781 (typeof ngDevMode === 'undefined' || ngDevMode) && `Cannot parse url '${this.url}'`,
782 );
783 }
784
785 let outletName: string | undefined;
786 if (path.indexOf(':') > -1) {
787 outletName = path.slice(0, path.indexOf(':'));
788 this.capture(outletName);
789 this.capture(':');
790 } else if (allowPrimary) {
791 outletName = PRIMARY_OUTLET;
792 }
793
794 const children = this.parseChildren(depth + 1);
795 segments[outletName ?? PRIMARY_OUTLET] =
796 Object.keys(children).length === 1 && children[PRIMARY_OUTLET]
797 ? children[PRIMARY_OUTLET]
798 : new UrlSegmentGroup([], children);
799 this.consumeOptional('//');
800 }
801
802 return segments;
803 }
804
805 private peekStartsWith(str: string): boolean {
806 return this.remaining.startsWith(str);

Callers 1

parseChildrenMethod · 0.95

Calls 7

captureMethod · 0.95
consumeOptionalMethod · 0.95
parseChildrenMethod · 0.95
matchSegmentsFunction · 0.85
indexOfMethod · 0.80
createMethod · 0.65
keysMethod · 0.65

Tested by

no test coverage detected