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

Method parseParens

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

Source from the content-addressed store, hash-verified

841
842 // parse `(a/b//outlet_name:c/d)`
843 private parseParens(allowPrimary: boolean, depth: number): {[outlet: string]: UrlSegmentGroup} {
844 // The outlet name is taken verbatim from the URL, so it can be `__proto__`. Indexing a plain
845 // object with that key assigns through the inherited `__proto__` setter instead of creating an
846 // outlet, which drops the outlet and mutates the map's prototype (and throws under Node's
847 // `--disable-proto=throw`). A null-prototype map makes `__proto__` an ordinary key.
848 const segments: {[key: string]: UrlSegmentGroup} = Object.create(null);
849 this.capture('(');
850
851 while (!this.consumeOptional(')') && this.remaining.length > 0) {
852 const path = matchSegments(this.remaining);
853
854 const next = this.remaining[path.length];
855
856 // if is is not one of these characters, then the segment was unescaped
857 // or the group was not closed
858 if (next !== '/' && next !== ')' && next !== ';') {
859 throw new RuntimeError(
860 RuntimeErrorCode.UNPARSABLE_URL,
861 (typeof ngDevMode === 'undefined' || ngDevMode) && `Cannot parse url '${this.url}'`,
862 );
863 }
864
865 let outletName: string | undefined;
866 if (path.indexOf(':') > -1) {
867 outletName = path.slice(0, path.indexOf(':'));
868 this.capture(outletName);
869 this.capture(':');
870 } else if (allowPrimary) {
871 outletName = PRIMARY_OUTLET;
872 }
873
874 const children = this.parseChildren(depth + 1);
875 const child =
876 Object.keys(children).length === 1 && children[PRIMARY_OUTLET]
877 ? children[PRIMARY_OUTLET]
878 : new UrlSegmentGroup([], children);
879 setUrlDerivedKey(segments, outletName ?? PRIMARY_OUTLET, child);
880 this.consumeOptional('//');
881 }
882
883 return segments;
884 }
885
886 private peekStartsWith(str: string): boolean {
887 return this.remaining.startsWith(str);

Callers 1

parseChildrenMethod · 0.95

Calls 9

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

Tested by

no test coverage detected