The file declaring `name` for code in `fromFile`: its import, else the file itself.
(name: string, fromFile: string, context: ResolutionContext)
| 590 | |
| 591 | /** The file declaring `name` for code in `fromFile`: its import, else the file itself. */ |
| 592 | function declaringFile(name: string, fromFile: string, context: ResolutionContext): string | null { |
| 593 | const content = context.readFile(fromFile); |
| 594 | if (!content) return null; |
| 595 | const imports = /\bimport\s*\{([^}]*)\}\s*from\s*(['"])([^'"]+)\2/g; |
| 596 | let m: RegExpExecArray | null; |
| 597 | while ((m = imports.exec(content)) !== null) { |
| 598 | const names = m[1]!.split(',').map((s) => s.trim().split(/\s+as\s+/).pop()!.trim()); |
| 599 | if (names.includes(name)) return resolveImportPath(m[3]!, fromFile, 'typescript', context); |
| 600 | } |
| 601 | return fromFile; |
| 602 | } |
| 603 | |
| 604 | // ============================================================================= |
| 605 | // Route table |
no test coverage detected