* The module whose namespace object `file` exports as `name`, when that * export is one (#2951): `export * as name from './m'`, or a namespace import * the file exports by clause, zod's `import * as z from './external.js'; * export { z }` — through named re-exports and `export *` lines, as the *
( file: string, name: string, language: Language, context: ResolutionContext, depth = 0, seen = new Set<string>(), )
| 3286 | * name itself, or exports no namespace by it. |
| 3287 | */ |
| 3288 | function namespaceExportModule( |
| 3289 | file: string, |
| 3290 | name: string, |
| 3291 | language: Language, |
| 3292 | context: ResolutionContext, |
| 3293 | depth = 0, |
| 3294 | seen = new Set<string>(), |
| 3295 | ): string | null { |
| 3296 | if (depth > REEXPORT_MAX_DEPTH || seen.has(file)) return null; |
| 3297 | seen.add(file); |
| 3298 | if (exportedByName(file, getFileExportIndex(file, context), name, context)) return null; |
| 3299 | const reExports = context.getReExports?.(file, language) ?? []; |
| 3300 | const namespaced = reExports.find((rex) => rex.kind === 'namespace' && rex.exportedName === name); |
| 3301 | if (namespaced) return resolveImportPath(namespaced.source, file, language, context); |
| 3302 | const source = context.readFile(file); |
| 3303 | if (source?.includes('export')) { |
| 3304 | for (const { exportedName, localName } of extractLocalExportAliases(source)) { |
| 3305 | if (exportedName !== name) continue; |
| 3306 | const imported = context.getImportMappings(file, language).find((m) => m.isNamespace && m.localName === localName); |
| 3307 | if (imported) return resolveImportPath(imported.source, file, language, context); |
| 3308 | } |
| 3309 | } |
| 3310 | for (const rex of reExports) { |
| 3311 | if (rex.kind !== 'wildcard' && !(rex.kind === 'named' && rex.exportedName === name)) continue; |
| 3312 | const next = resolveImportPath(rex.source, file, language, context); |
| 3313 | const found = next ? namespaceExportModule(next, rex.kind === 'named' ? rex.originalName : name, language, context, depth + 1, seen) : null; |
| 3314 | if (found) return found; |
| 3315 | } |
| 3316 | return null; |
| 3317 | } |
| 3318 | |
| 3319 | export function resolveViaImport( |
| 3320 | ref: UnresolvedRef, |
no test coverage detected