MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / namespaceExportModule

Function namespaceExportModule

src/resolution/import-resolver.ts:3290–3319  ·  view source on GitHub ↗

* 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>(),
)

Source from the content-addressed store, hash-verified

3288 * name itself, or exports no namespace by it.
3289 */
3290function namespaceExportModule(
3291 file: string,
3292 name: string,
3293 language: Language,
3294 context: ResolutionContext,
3295 depth = 0,
3296 seen = new Set<string>(),
3297): string | null {
3298 if (depth > REEXPORT_MAX_DEPTH || seen.has(file)) return null;
3299 seen.add(file);
3300 if (exportedByName(file, getFileExportIndex(file, context), name, context)) return null;
3301 const reExports = context.getReExports?.(file, language) ?? [];
3302 const namespaced = reExports.find((rex) => rex.kind === 'namespace' && rex.exportedName === name);
3303 if (namespaced) return resolveImportPath(namespaced.source, file, language, context);
3304 const source = context.readFile(file);
3305 if (source?.includes('export')) {
3306 for (const { exportedName, localName } of extractLocalExportAliases(source)) {
3307 if (exportedName !== name) continue;
3308 const imported = context.getImportMappings(file, language).find((m) => m.isNamespace && m.localName === localName);
3309 if (imported) return resolveImportPath(imported.source, file, language, context);
3310 }
3311 }
3312 for (const rex of reExports) {
3313 if (rex.kind !== 'wildcard' && !(rex.kind === 'named' && rex.exportedName === name)) continue;
3314 const next = resolveImportPath(rex.source, file, language, context);
3315 const found = next ? namespaceExportModule(next, rex.kind === 'named' ? rex.originalName : name, language, context, depth + 1, seen) : null;
3316 if (found) return found;
3317 }
3318 return null;
3319}
3320
3321export function resolveViaImport(
3322 ref: UnresolvedRef,

Callers 1

resolveViaImportFunction · 0.85

Calls 9

exportedByNameFunction · 0.85
getFileExportIndexFunction · 0.85
resolveImportPathFunction · 0.85
hasMethod · 0.80
getReExportsMethod · 0.80
getImportMappingsMethod · 0.80
readFileMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected