( relativePath: string, language: Language, context: ResolutionContext, exists: (file: string) => boolean = (file) => context.fileExists(file) )
| 1723 | ]; |
| 1724 | |
| 1725 | function findSourceForEmittedSpecifier( |
| 1726 | relativePath: string, |
| 1727 | language: Language, |
| 1728 | context: ResolutionContext, |
| 1729 | exists: (file: string) => boolean = (file) => context.fileExists(file) |
| 1730 | ): string | null { |
| 1731 | if (!EMITTED_SPECIFIER_LANGUAGES.has(language)) return null; |
| 1732 | for (const [emitted, sources] of EMITTED_TO_SOURCE_EXTENSIONS) { |
| 1733 | if (!emitted.test(relativePath)) continue; |
| 1734 | const stem = relativePath.replace(emitted, ''); |
| 1735 | for (const ext of sources) { |
| 1736 | const candidate = stem + ext; |
| 1737 | if (exists(candidate)) return candidate; |
| 1738 | } |
| 1739 | return null; |
| 1740 | } |
| 1741 | return null; |
| 1742 | } |
| 1743 | |
| 1744 | /** Languages whose import specifiers can name the emitted `.js` of a `.ts` source. */ |
| 1745 | const EMITTED_SPECIFIER_LANGUAGES: ReadonlySet<string> = new Set([ |
no test coverage detected