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

Function resolveComponent

src/resolution/frameworks/react.ts:2440–2466  ·  view source on GitHub ↗

* Resolve a component reference using name-based lookup

(
  name: string,
  fromFile: string,
  context: ResolutionContext
)

Source from the content-addressed store, hash-verified

2438 * Resolve a component reference using name-based lookup
2439 */
2440function resolveComponent(
2441 name: string,
2442 fromFile: string,
2443 context: ResolutionContext
2444): string | null {
2445 const candidates = context.getNodesByName(name);
2446 if (candidates.length === 0) return null;
2447
2448 const components = candidates.filter((n) => COMPONENT_KINDS.has(n.kind));
2449 if (components.length === 0) return null;
2450
2451 // Prefer the referencing file's folder, or one below it
2452 const sameDir = inReferencingFolder(fromFile, components, (n) => n.filePath);
2453 if (sameDir.length > 0) return sameDir[0]!.id;
2454
2455 // Prefer component directories
2456 const COMPONENT_DIRS = ['/components/', '/src/components/', '/app/components/', '/pages/', '/src/pages/', '/views/', '/src/views/'];
2457 const preferred = components.filter((n) =>
2458 COMPONENT_DIRS.some((d) => n.filePath.includes(d))
2459 );
2460 if (preferred.length > 0) return preferred[0]!.id;
2461
2462 // No positional signal: only an UNAMBIGUOUS name may resolve. Returning
2463 // components[0] here picked an arbitrary same-named class anywhere in the
2464 // repo (#764) — let the name-matcher's proximity scoring decide instead.
2465 return components.length === 1 ? components[0]!.id : null;
2466}
2467
2468/** JS/TS (and their JSX dialects): modules where a cross-file name needs an import. */
2469function isEsmLanguage(language?: string): boolean {

Callers 2

resolveFunction · 0.70
layoutComponentFunction · 0.70

Calls 3

inReferencingFolderFunction · 0.90
hasMethod · 0.80
getNodesByNameMethod · 0.65

Tested by

no test coverage detected