MCPcopy Index your code
hub / github.com/angular/angular / tree

Function tree

packages/router/src/create_url_tree.ts:182–214  ·  view source on GitHub ↗
(
  oldRoot: UrlSegmentGroup,
  oldSegmentGroup: UrlSegmentGroup,
  newSegmentGroup: UrlSegmentGroup,
  queryParams: Params | null,
  fragment: string | null,
  urlSerializer: UrlSerializer,
)

Source from the content-addressed store, hash-verified

180}
181
182function tree(
183 oldRoot: UrlSegmentGroup,
184 oldSegmentGroup: UrlSegmentGroup,
185 newSegmentGroup: UrlSegmentGroup,
186 queryParams: Params | null,
187 fragment: string | null,
188 urlSerializer: UrlSerializer,
189): UrlTree {
190 const qp: Params = {};
191 for (const [key, value] of Object.entries(queryParams ?? {})) {
192 // This retains old behavior where each item in the array was stringified individually This
193 // helps remove special-case handling for empty and single-item arrays where the default
194 // serializer removes empty arrays when serialized then parsed or converts them to non-arrays
195 // for single-item arrays. Changing this could have breaking change implications. Prior code
196 // always returned arrays of strings for array inputs so tests, applications, serializers,
197 // etc. may only be set up to handle string arrays. We could consider changing this in the
198 // future to serialize the entire array as a single value. For now, this feels safer and is
199 // at least a step in the right direction.
200 qp[key] = Array.isArray(value)
201 ? value.map((v) => normalizeQueryParams(key, v, urlSerializer))
202 : normalizeQueryParams(key, value, urlSerializer);
203 }
204
205 let rootCandidate: UrlSegmentGroup;
206 if (oldRoot === oldSegmentGroup) {
207 rootCandidate = newSegmentGroup;
208 } else {
209 rootCandidate = replaceSegment(oldRoot, oldSegmentGroup, newSegmentGroup);
210 }
211
212 const newRoot = createRoot(squashSegmentGroup(rootCandidate));
213 return new UrlTree(newRoot, qp, fragment);
214}
215
216/**
217 * Replaces the `oldSegment` which is located in some child of the `current` with the `newSegment`.

Callers 1

Calls 7

createRootFunction · 0.90
squashSegmentGroupFunction · 0.90
replaceSegmentFunction · 0.85
isArrayMethod · 0.80
mapMethod · 0.80
normalizeQueryParamsFunction · 0.70
entriesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…