* The string a member expression like `paths.app.root.path` reads from a * constant object literal — the constant found through the route file's * import of its root name, or in the file itself.
(expr: string, fromFile: string, context: ResolutionContext)
| 302 | * import of its root name, or in the file itself. |
| 303 | */ |
| 304 | function constantPathValue(expr: string, fromFile: string, context: ResolutionContext): string | null { |
| 305 | const [root, ...keys] = expr.split('.'); |
| 306 | if (!root || keys.length === 0) return null; |
| 307 | let file = fromFile; |
| 308 | let name = root; |
| 309 | const mapping = context.getImportMappings(fromFile, 'tsx').find((m) => m.localName === root) ?? |
| 310 | context.getImportMappings(fromFile, 'typescript').find((m) => m.localName === root); |
| 311 | if (mapping) { |
| 312 | const resolved = resolveImportPath(mapping.source, fromFile, 'typescript', context); |
| 313 | if (!resolved) return null; |
| 314 | file = resolved; |
| 315 | if (mapping.exportedName && mapping.exportedName !== 'default' && mapping.exportedName !== '*') name = mapping.exportedName; |
| 316 | } |
| 317 | const decl = context.getNodesInFile(file).find((n) => n.name === name && (n.kind === 'constant' || n.kind === 'variable')); |
| 318 | if (!decl) return null; |
| 319 | const lines = context.readFile(file)?.split('\n') ?? []; |
| 320 | const text = lines.slice(decl.startLine - 1, decl.endLine).join('\n'); |
| 321 | const open = text.indexOf('{', Math.max(0, text.search(new RegExp(`\\b${escapeRegExp(name)}\\b`)))); |
| 322 | return open < 0 ? null : readObjectPath(text, open, keys); |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * The href a route-config object names — `paths.app.discussion.getHref(id)` |
no test coverage detected