* Every screen whose component reaches `holder` through calls, each with the * shortest chain (breadth-first). `[]` when none does within the caps but the * walk completed; `null` when the walk was cut short — a hub so wide the * answer would be a guess.
( cg: CodeGraph, projectRoot: string, holder: Node, screenOfComponent: Map<string, string[]>, routeByFile: Map<string, string>, known: Map<string, Node> )
| 448 | * answer would be a guess. |
| 449 | */ |
| 450 | async function attribute( |
| 451 | cg: CodeGraph, |
| 452 | projectRoot: string, |
| 453 | holder: Node, |
| 454 | screenOfComponent: Map<string, string[]>, |
| 455 | routeByFile: Map<string, string>, |
| 456 | known: Map<string, Node> |
| 457 | ): Promise<Attribution[] | null> { |
| 458 | // The holder IS a screen component: the transition starts on that screen — |
| 459 | // on each of them, when one component is rendered at several addresses. |
| 460 | const own = screenOfComponent.get(holder.id); |
| 461 | if (own) return own.map((screenId) => ({ screenId, path: [{ node: holder, edge: null }] })); |
| 462 | |
| 463 | const parent = new Map<string, { prev: string | null; edge: Edge | null }>(); |
| 464 | parent.set(holder.id, { prev: null, edge: null }); |
| 465 | const nodes = new Map<string, Node>([[holder.id, holder]]); |
| 466 | let frontier = [holder.id]; |
| 467 | const found: Attribution[] = []; |
| 468 | let truncated = false; |
| 469 | |
| 470 | for (let depth = 0; depth < MAX_DEPTH && frontier.length > 0; depth++) { |
| 471 | const incoming = cg.getIncomingEdgesTo(frontier, WALK_KINDS); |
| 472 | const byTarget = new Map<string, Edge[]>(); |
| 473 | for (const e of incoming) { |
| 474 | if (e.kind === 'references' && (e.metadata as Record<string, unknown> | undefined)?.fnRef !== true) continue; |
| 475 | if (arrivesFromAnotherContext(e)) continue; |
| 476 | const list = byTarget.get(e.target) ?? []; |
| 477 | list.push(e); |
| 478 | byTarget.set(e.target, list); |
| 479 | } |
| 480 | // A value nothing calls — `export const signIn = validatedAction(schema, |
| 481 | // async (data) => { … redirect('/dashboard') })`, handed to |
| 482 | // `useActionState(signIn, …)` as a plain argument the graph keeps no |
| 483 | // function-as-value edge for — is used wherever a function in a file that |
| 484 | // imports it names it. Those mentions are its callers, read from the source. |
| 485 | for (const id of frontier) { |
| 486 | const value = nodes.get(id); |
| 487 | if (!value || (value.kind !== 'constant' && value.kind !== 'variable')) continue; |
| 488 | // The file that declares the value `contains` it; that is not a caller. |
| 489 | const callers = (byTarget.get(id) ?? []).filter((e) => e.kind !== 'contains'); |
| 490 | if (callers.length > 0) continue; |
| 491 | const mentions = mentionsOf(cg, projectRoot, value); |
| 492 | if (mentions.length > 0) byTarget.set(id, [...callers, ...mentions]); |
| 493 | } |
| 494 | const nextIds: string[] = []; |
| 495 | const wanted = new Set<string>(); |
| 496 | for (const [, edges] of byTarget) { |
| 497 | if (edges.length > MAX_CALLERS_PER_NODE) { |
| 498 | truncated = true; |
| 499 | continue; |
| 500 | } |
| 501 | for (const e of edges) if (!parent.has(e.source)) wanted.add(e.source); |
| 502 | } |
| 503 | if (parent.size + wanted.size > MAX_VISITED) truncated = true; |
| 504 | const fetched = wanted.size === 0 ? new Map<string, Node>() : cg.getNodesByIds([...wanted]); |
| 505 | for (const [, edges] of byTarget) { |
| 506 | if (edges.length > MAX_CALLERS_PER_NODE) continue; |
| 507 | for (const e of edges) { |
no test coverage detected