(filePath: string, content: string)
| 249 | }, |
| 250 | |
| 251 | extract(filePath: string, content: string) { |
| 252 | const file = nextRouteForFile(filePath); |
| 253 | if (!file) return { nodes: [], references: [] }; |
| 254 | const language = languageForFile(filePath); |
| 255 | const now = Date.now(); |
| 256 | const nodes: Node[] = []; |
| 257 | const references: UnresolvedRef[] = []; |
| 258 | const stripped = stripCommentsForRegex(content, 'typescript'); |
| 259 | const lineOf = (index: number): number => stripped.slice(0, index).split('\n').length; |
| 260 | |
| 261 | if (file.kind === 'handler') { |
| 262 | // `export async function GET(req) {…}` / `export const POST = …` — one route per method. |
| 263 | const seen = new Set<string>(); |
| 264 | const decl = new RegExp(`\\bexport\\s+(?:async\\s+)?function\\s+(${HTTP_EXPORTS})\\b|\\bexport\\s+(?:const|let)\\s+(${HTTP_EXPORTS})\\s*=`, 'g'); |
| 265 | let m: RegExpExecArray | null; |
| 266 | while ((m = decl.exec(stripped)) !== null) { |
| 267 | const method = (m[1] ?? m[2])!; |
| 268 | if (seen.has(method)) continue; |
| 269 | seen.add(method); |
| 270 | const line = lineOf(m.index); |
| 271 | const node: Node = { |
| 272 | id: `route:${filePath}:${line}:${method}:${file.path}`, |
| 273 | kind: 'route', |
| 274 | name: `${method} ${file.path}`, |
| 275 | qualifiedName: `${filePath}::${method}:${file.path}`, |
| 276 | filePath, |
| 277 | startLine: line, |
| 278 | endLine: line, |
| 279 | startColumn: 0, |
| 280 | endColumn: m[0].length, |
| 281 | language, |
| 282 | isExported: true, |
| 283 | updatedAt: now, |
| 284 | }; |
| 285 | nodes.push(node); |
| 286 | references.push({ fromNodeId: node.id, referenceName: method, referenceKind: 'references', line, column: 0, filePath, language, candidates: [method] }); |
| 287 | } |
| 288 | return { nodes, references }; |
| 289 | } |
| 290 | |
| 291 | // A page, or a Pages Router API file: the default export is what runs. |
| 292 | const name = file.kind === 'api' ? `ANY ${file.path}` : file.path; |
| 293 | const node: Node = { |
| 294 | id: file.kind === 'api' ? `route:${filePath}:1:ANY:${file.path}` : `route:${filePath}:${file.path}`, |
| 295 | kind: 'route', |
| 296 | name, |
| 297 | qualifiedName: file.kind === 'api' ? `${filePath}::ANY:${file.path}` : `${filePath}::route:${file.path}`, |
| 298 | filePath, |
| 299 | startLine: 1, |
| 300 | endLine: 1, |
| 301 | startColumn: 0, |
| 302 | endColumn: 0, |
| 303 | language, |
| 304 | isExported: true, |
| 305 | updatedAt: now, |
| 306 | }; |
| 307 | nodes.push(node); |
| 308 | const exported = defaultExportName(stripped); |
nothing calls this directly
no test coverage detected