* Resolve a Svelte component reference using name-based lookup
( name: string, fromFile: string, context: ResolutionContext )
| 216 | * Resolve a Svelte component reference using name-based lookup |
| 217 | */ |
| 218 | function 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 |
no test coverage detected