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

Function namespaceExportModule

src/resolution/import-resolver.ts:3536–3565  ·  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

3534 * name itself, or exports no namespace by it.
3535 */
3536function namespaceExportModule(
3537 file: string,
3538 name: string,
3539 language: Language,
3540 context: ResolutionContext,
3541 depth = 0,
3542 seen = new Set<string>(),
3543): string | null {
3544 if (depth > REEXPORT_MAX_DEPTH || seen.has(file)) return null;
3545 seen.add(file);
3546 if (exportedByName(file, getFileExportIndex(file, context), name, context)) return null;
3547 const reExports = context.getReExports?.(file, language) ?? [];
3548 const namespaced = reExports.find((rex) => rex.kind === 'namespace' && rex.exportedName === name);
3549 if (namespaced) return resolveImportPath(namespaced.source, file, language, context);
3550 const source = context.readFile(file);
3551 if (source?.includes('export')) {
3552 for (const { exportedName, localName } of extractLocalExportAliases(source)) {
3553 if (exportedName !== name) continue;
3554 const imported = context.getImportMappings(file, language).find((m) => m.isNamespace && m.localName === localName);
3555 if (imported) return resolveImportPath(imported.source, file, language, context);
3556 }
3557 }
3558 for (const rex of reExports) {
3559 if (rex.kind !== 'wildcard' && !(rex.kind === 'named' && rex.exportedName === name)) continue;
3560 const next = resolveImportPath(rex.source, file, language, context);
3561 const found = next ? namespaceExportModule(next, rex.kind === 'named' ? rex.originalName : name, language, context, depth + 1, seen) : null;
3562 if (found) return found;
3563 }
3564 return null;
3565}
3566
3567export function resolveViaImport(
3568 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