MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / walk

Function walk

src/resolution/frameworks/angular-router.ts:265–331  ·  view source on GitHub ↗
(open: number, close: number, prefix: readonly string[], depth: number, layouts: readonly AngularComponentRef[])

Source from the content-addressed store, hash-verified

263 const walked = new Set<number>();
264
265 const walk = (open: number, close: number, prefix: readonly string[], depth: number, layouts: readonly AngularComponentRef[]): void => {
266 if (walked.has(open) || depth > 12) return;
267 walked.add(open);
268 for (const obj of topLevelObjects(safe, open + 1, close)) {
269 const fields = readFields(safe, obj.start, obj.end);
270 if (!ROUTE_KEYS.some((k) => fields.has(k))) continue;
271 // A custom `matcher` decides the address at run time — no path to name.
272 if (fields.has('matcher')) continue;
273 const pathField = fields.get('path');
274 // `{ path: '**', redirectTo: 'home' }`: where an address nothing else matches lands.
275 if (pathField && fields.has('redirectTo') && staticString(pathField.text) === '**') {
276 const target = staticString(fields.get('redirectTo')!.text);
277 if (target !== null && !target.includes('**')) {
278 const absolute = target.startsWith('/');
279 redirects.push({ from: joinPath([...prefix, '**']), to: joinPath([...(absolute ? [] : prefix), ...target.split('/').filter((t) => t.length > 0)]), absolute });
280 }
281 continue;
282 }
283 const own = pathField ? pathSegments(pathField.text) : [];
284 if (own === null) continue; // a computed path, or a `**` catch-all
285 const segs = [...prefix, ...own];
286 const line = lineOf(pathField ? pathField.at : obj.start);
287
288 const redirectTo = fields.get('redirectTo');
289 if (redirectTo) {
290 // `{ path: '', redirectTo: 'home' }`: arriving at `/` is arriving at
291 // `/home`. A relative target is a sibling, under the same parent.
292 const target = staticString(redirectTo.text);
293 if (target !== null && !target.includes('**')) {
294 const absolute = target.startsWith('/');
295 const to = joinPath([...(absolute ? [] : prefix), ...target.split('/').filter((t) => t.length > 0)]);
296 redirects.push({ from: joinPath(segs), to, absolute });
297 }
298 continue;
299 }
300
301 const loadChildren = fields.get('loadChildren');
302 if (loadChildren) {
303 const lazy = lazyImport(loadChildren.text);
304 if (lazy) mounts.push({ prefix: joinPath(segs), spec: lazy.spec, line });
305 continue;
306 }
307 const componentField = fields.get('component') ? 'component' : fields.get('loadComponent') ? 'loadComponent' : null;
308 const component = componentField ? componentRef(componentField, fields.get(componentField)!.text) : null;
309
310 const children = fields.get('children');
311 let childClaimsAddress = false;
312 if (children) {
313 const childOpen = safe.indexOf('[', children.at);
314 const childClose = childOpen < 0 ? -1 : matchBracket(safe, childOpen);
315 if (childOpen >= 0 && childClose > childOpen) {
316 for (const child of topLevelObjects(safe, childOpen + 1, childClose)) {
317 const childPath = readFields(safe, child.start, child.end).get('path');
318 if (!childPath || pathSegments(childPath.text)?.length === 0) childClaimsAddress = true;
319 }
320 walk(childOpen, childClose, segs, depth + 1, component ? [...layouts, component] : layouts);
321 }
322 }

Callers 1

parseAngularRoutesFunction · 0.70

Calls 13

topLevelObjectsFunction · 0.90
readFieldsFunction · 0.90
matchBracketFunction · 0.90
staticStringFunction · 0.85
pathSegmentsFunction · 0.85
lazyImportFunction · 0.85
componentRefFunction · 0.85
hasMethod · 0.80
pushMethod · 0.80
joinPathFunction · 0.70
lineOfFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected