* The file and variable an `include_router` argument names: `items.router` * through the module's import, `items_router` through an alias import, or a * router defined in the same file.
( expr: string, file: string, local: Map<string, string>, context: ResolutionContext )
| 408 | * router defined in the same file. |
| 409 | */ |
| 410 | function includedRouter( |
| 411 | expr: string, |
| 412 | file: string, |
| 413 | local: Map<string, string>, |
| 414 | context: ResolutionContext |
| 415 | ): { file: string; variable: string } | null { |
| 416 | const segs = expr.split('.'); |
| 417 | const head = segs[0]!; |
| 418 | if (segs.length === 1 && local.has(head)) return { file, variable: head }; |
| 419 | const mapping = context.getImportMappings(file, 'python').find((im) => im.localName === head); |
| 420 | if (!mapping) return null; |
| 421 | if (segs.length > 1) { |
| 422 | // `items.router`: `items` is a module — `from app.api.routes import items`. |
| 423 | const moduleFile = resolveImportPath(`${mapping.source}.${mapping.exportedName}`, file, 'python', context) ?? resolveImportPath(mapping.source, file, 'python', context); |
| 424 | return moduleFile ? { file: moduleFile, variable: segs[segs.length - 1]! } : null; |
| 425 | } |
| 426 | // `items_router`: `from .items import router as items_router`. |
| 427 | const moduleFile = resolveImportPath(mapping.source, file, 'python', context); |
| 428 | return moduleFile ? { file: moduleFile, variable: mapping.exportedName } : null; |
| 429 | } |
| 430 | |
| 431 | interface DecoratorRouteOpts { |
| 432 | decoratorRegex: RegExp; |
no test coverage detected