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

Function importedTypeMember

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

* A type path through an import of the file's: the module's export the path * starts with (`T.X`, through barrels and the repository's `declare module` * blocks), or the member of the enum, class or namespace the import names. * null for a package the repository doesn't declare, or a container wi

(imp: ImportMapping, path: string[], ref: UnresolvedRef, context: ResolutionContext)

Source from the content-addressed store, hash-verified

3026 * the member; undefined when the module's export can't be followed.
3027 */
3028function importedTypeMember(imp: ImportMapping, path: string[], ref: UnresolvedRef, context: ResolutionContext): Node | null | undefined {
3029 const file = resolveImportPath(imp.source, ref.filePath, ref.language, context);
3030 let found: Node | undefined;
3031 let rest: string[];
3032 if (imp.isNamespace) {
3033 const want = { isDefault: false, isNamespace: true, exportedName: path[0]!, memberName: path[0]! };
3034 found = findImportedExport(imp.source, file, want, ref, context);
3035 if (found && path.length === 1) return found;
3036 rest = path.slice(1);
3037 } else {
3038 const want = { isDefault: imp.isDefault, isNamespace: false, exportedName: imp.isDefault ? 'default' : imp.exportedName, memberName: null };
3039 found = findImportedExport(imp.source, file, want, ref, context);
3040 rest = path;
3041 }
3042 if (found) {
3043 const member = STATIC_MEMBER_CONTAINERS.has(found.kind) ? containerMember(found, rest, context) : undefined;
3044 return member ?? typeMemberIn(found.filePath, [], [found.name, ...rest], context) ?? null;
3045 }
3046 // A namespace the module declares, for which the index holds no node.
3047 const namespace = imp.isNamespace ? path[0]! : imp.isDefault ? null : imp.exportedName;
3048 const declaring = file && namespace ? namespaceDeclaringFile(file, namespace, ref.language, context) : undefined;
3049 if (declaring) return typeMemberIn(declaring.file, [], [declaring.name, ...rest], context) ?? null;
3050 // A package from outside the repository, which it doesn't declare itself:
3051 // its type is no project node. An import this resolver can't follow but no
3052 // manifest declares, like zod's own tests' `import * as z from "zod/v3"`
3053 // through the package's `exports`, keeps the ordinary strategies.
3054 const outside = !file && !findAmbientModuleFile(imp.source, ref.filePath, context) &&
3055 context.isOutOfRepoImport?.(imp.source, ref.filePath, ref.language) === true;
3056 return outside ? null : undefined;
3057}
3058
3059/**
3060 * A type path through what the file declares itself as `head`: in the

Callers 1

Calls 8

findAmbientModuleFileFunction · 0.90
resolveImportPathFunction · 0.85
findImportedExportFunction · 0.85
containerMemberFunction · 0.85
typeMemberInFunction · 0.85
namespaceDeclaringFileFunction · 0.85
hasMethod · 0.80
isOutOfRepoImportMethod · 0.80

Tested by

no test coverage detected