(ref: UnresolvedRef, context: ResolutionContext)
| 147 | }, |
| 148 | |
| 149 | resolve(ref: UnresolvedRef, context: ResolutionContext): ResolvedRef | null { |
| 150 | // A JS/TS module reaches another file's middleware, controller or service |
| 151 | // only through an `import` / `require` — the import resolver's — never by |
| 152 | // name: SvelteKit's remote functions' `validate(arg)` went to the config |
| 153 | // loader's `validate` in another package. The patterns below stay for the |
| 154 | // file's own declarations. |
| 155 | const sameFile = (id: string | null): string | null => |
| 156 | id !== null && context.getNodeById?.(id)?.filePath === ref.filePath ? id : null; |
| 157 | // Pattern 1: Middleware references |
| 158 | if (isMiddlewareName(ref.referenceName)) { |
| 159 | const result = sameFile(resolveMiddleware(ref.referenceName, context, ref.filePath)); |
| 160 | if (result) { |
| 161 | return { |
| 162 | original: ref, |
| 163 | targetNodeId: result, |
| 164 | confidence: 0.8, |
| 165 | resolvedBy: 'framework', |
| 166 | }; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | // Pattern 2: Controller method references |
| 171 | const controllerMatch = ref.referenceName.match(/^(\w+)Controller\.(\w+)$/); |
| 172 | if (controllerMatch) { |
| 173 | const [, controller, method] = controllerMatch; |
| 174 | const result = sameFile(resolveControllerMethod(controller!, method!, context)); |
| 175 | if (result) { |
| 176 | return { |
| 177 | original: ref, |
| 178 | targetNodeId: result, |
| 179 | confidence: 0.85, |
| 180 | resolvedBy: 'framework', |
| 181 | }; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | // Pattern 3: Service/helper references |
| 186 | const serviceMatch = ref.referenceName.match(/^(\w+)(Service|Helper|Utils?)\.(\w+)$/); |
| 187 | if (serviceMatch) { |
| 188 | const [, name, suffix, method] = serviceMatch; |
| 189 | const result = sameFile(resolveServiceMethod(name! + suffix!, method!, context)); |
| 190 | if (result) { |
| 191 | return { |
| 192 | original: ref, |
| 193 | targetNodeId: result, |
| 194 | confidence: 0.8, |
| 195 | resolvedBy: 'framework', |
| 196 | }; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | return null; |
| 201 | }, |
| 202 | |
| 203 | extract(filePath, content) { |
| 204 | if (!/\.(m?js|tsx?|cjs)$/.test(filePath)) return { nodes: [], references: [] }; |
nothing calls this directly
no test coverage detected