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