(ref: UnresolvedRef, context: ResolutionContext)
| 322 | }, |
| 323 | |
| 324 | resolve(ref: UnresolvedRef, context: ResolutionContext): ResolvedRef | null { |
| 325 | if (ref.referenceKind !== 'calls') return null; |
| 326 | const verb = nextNavVerb(ref.referenceName); |
| 327 | if (!verb) return null; |
| 328 | if (!ROUTE_LANGUAGES.includes(ref.language)) return null; |
| 329 | const table = nextRouteTable(context); |
| 330 | if (table.exact.size === 0 || !table.roots.some((root) => ref.filePath.startsWith(root))) return null; |
| 331 | const callee = ref.referenceName.slice(ref.referenceName.lastIndexOf('.') + 1); |
| 332 | const lines = context.getFileLines?.(ref.filePath) ?? context.readFile(ref.filePath)?.split(/\r?\n/) ?? null; |
| 333 | if (!lines) return null; |
| 334 | |
| 335 | let arg = firstArgumentText(lines, ref.line, ref.column, callee); |
| 336 | if (arg === null) return null; |
| 337 | // `NextResponse.redirect(new URL('/login', req.url))` — the path is the URL's first argument. |
| 338 | if (/^\s*new\s+URL\s*\(/.test(arg)) arg = firstArgumentText([arg], 1, 0, 'URL'); |
| 339 | let href = arg === null ? null : parseHrefExpression(arg); |
| 340 | if (!href) { |
| 341 | const enclosing = context.getNodeById?.(ref.fromNodeId); |
| 342 | const start = enclosing && enclosing.filePath === ref.filePath ? enclosing.startLine : Math.max(1, ref.line - 40); |
| 343 | href = readHrefViaLocal(lines, ref.line, ref.column, callee, start); |
| 344 | } |
| 345 | if (!href) return null; |
| 346 | // Every arm of a conditional destination is somewhere this call goes; the |
| 347 | // first is this reference's resolution and the rest ride as `alsoTargets`. |
| 348 | const targets = destinationsForHref(href, table); |
| 349 | const target = targets[0]; |
| 350 | if (!target) return null; |
| 351 | return { |
| 352 | original: ref, |
| 353 | targetNodeId: target.node.id, |
| 354 | ...(targets.length > 1 |
| 355 | ? { alsoTargets: targets.slice(1).map((t) => ({ targetNodeId: t.node.id, metadata: { href: t.href.display, navMethod: verb } })) } |
| 356 | : {}), |
| 357 | confidence: 0.95, |
| 358 | resolvedBy: 'framework', |
| 359 | edgeKind: 'navigates', |
| 360 | metadata: { href: target.href.display, navMethod: verb }, |
| 361 | }; |
| 362 | }, |
| 363 | }; |
nothing calls this directly
no test coverage detected