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

Function resolveComponent

src/resolution/frameworks/react.ts:2418–2444  ·  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

2416 * Resolve a component reference using name-based lookup
2417 */
2418function resolveComponent(
2419 name: string,
2420 fromFile: string,
2421 context: ResolutionContext
2422): string | null {
2423 const candidates = context.getNodesByName(name);
2424 if (candidates.length === 0) return null;
2425
2426 const components = candidates.filter((n) => COMPONENT_KINDS.has(n.kind));
2427 if (components.length === 0) return null;
2428
2429 // Prefer the referencing file's folder, or one below it
2430 const sameDir = inReferencingFolder(fromFile, components, (n) => n.filePath);
2431 if (sameDir.length > 0) return sameDir[0]!.id;
2432
2433 // Prefer component directories
2434 const COMPONENT_DIRS = ['/components/', '/src/components/', '/app/components/', '/pages/', '/src/pages/', '/views/', '/src/views/'];
2435 const preferred = components.filter((n) =>
2436 COMPONENT_DIRS.some((d) => n.filePath.includes(d))
2437 );
2438 if (preferred.length > 0) return preferred[0]!.id;
2439
2440 // No positional signal: only an UNAMBIGUOUS name may resolve. Returning
2441 // components[0] here picked an arbitrary same-named class anywhere in the
2442 // repo (#764) — let the name-matcher's proximity scoring decide instead.
2443 return components.length === 1 ? components[0]!.id : null;
2444}
2445
2446/** JS/TS (and their JSX dialects): modules where a cross-file name needs an import. */
2447function 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