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

Function importedTypeMember

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

3127 * the member; undefined when the module's export can't be followed.
3128 */
3129function importedTypeMember(imp: ImportMapping, path: string[], ref: UnresolvedRef, context: ResolutionContext): Node | null | undefined {
3130 const file = resolveImportPath(imp.source, ref.filePath, ref.language, context);
3131 let found: Node | undefined;
3132 let rest: string[];
3133 if (imp.isNamespace) {
3134 const want = { isDefault: false, isNamespace: true, exportedName: path[0]!, memberName: path[0]! };
3135 found = findImportedExport(imp.source, file, want, ref, context);
3136 if (found && path.length === 1) return found;
3137 rest = path.slice(1);
3138 } else {
3139 const want = { isDefault: imp.isDefault, isNamespace: false, exportedName: imp.isDefault ? 'default' : imp.exportedName, memberName: null };
3140 found = findImportedExport(imp.source, file, want, ref, context);
3141 rest = path;
3142 }
3143 if (found) {
3144 const member = STATIC_MEMBER_CONTAINERS.has(found.kind) ? containerMember(found, rest, context) : undefined;
3145 return member ?? typeMemberIn(found.filePath, [], [found.name, ...rest], context) ?? null;
3146 }
3147 // A namespace the module declares, for which the index holds no node.
3148 const namespace = imp.isNamespace ? path[0]! : imp.isDefault ? null : imp.exportedName;
3149 const declaring = file && namespace ? namespaceDeclaringFile(file, namespace, ref.language, context) : undefined;
3150 if (declaring) return typeMemberIn(declaring.file, [], [declaring.name, ...rest], context) ?? null;
3151 // A package from outside the repository, which it doesn't declare itself:
3152 // its type is no project node. An import this resolver can't follow but no
3153 // manifest declares, like zod's own tests' `import * as z from "zod/v3"`
3154 // through the package's `exports`, keeps the ordinary strategies.
3155 const outside = !file && !findAmbientModuleFile(imp.source, ref.filePath, context) &&
3156 context.isOutOfRepoImport?.(imp.source, ref.filePath, ref.language) === true;
3157 return outside ? null : undefined;
3158}
3159
3160/**
3161 * 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