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

Function resolveComponent

src/resolution/frameworks/svelte.ts:218–238  ·  view source on GitHub ↗

* Resolve a Svelte component reference using name-based lookup

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

Source from the content-addressed store, hash-verified

216 * Resolve a Svelte component reference using name-based lookup
217 */
218function resolveComponent(
219 name: string,
220 fromFile: string,
221 context: ResolutionContext
222): string | null {
223 // Look for component nodes by name
224 const candidates = context.getNodesByName(name);
225 const components = candidates.filter((n) => n.kind === 'component');
226
227 if (components.length === 0) return null;
228
229 // Prefer the referencing file's folder, or one below it
230 const sameDir = inReferencingFolder(fromFile, components, (n) => n.filePath);
231 if (sameDir.length > 0) return sameDir[0]!.id;
232
233 // No positional signal: only an UNAMBIGUOUS name may resolve — picking
234 // components[0] chose an arbitrary same-named component in a multi-app
235 // monorepo (#764). Ambiguity falls through to the name-matcher, whose
236 // proximity scoring decides.
237 return components.length === 1 ? components[0]!.id : null;
238}
239
240/**
241 * SvelteKit route file patterns

Callers 1

resolveFunction · 0.70

Calls 2

inReferencingFolderFunction · 0.90
getNodesByNameMethod · 0.65

Tested by

no test coverage detected