MCPcopy Create free account
hub / github.com/reactjs/react-docgen / findScopePath

Function findScopePath

packages/react-docgen/src/utils/resolveToValue.ts:14–56  ·  view source on GitHub ↗
(
  bindingIdentifiers: Array<NodePath<Identifier>> | undefined,
)

Source from the content-addressed store, hash-verified

12import getNameOrValue from './getNameOrValue.js';
13
14function findScopePath(
15 bindingIdentifiers: Array<NodePath<Identifier>> | undefined,
16): NodePath | null {
17 if (bindingIdentifiers && bindingIdentifiers[0]) {
18 const resolvedParentPath = bindingIdentifiers[0].parentPath;
19
20 if (
21 resolvedParentPath.isImportDefaultSpecifier() ||
22 resolvedParentPath.isImportSpecifier()
23 ) {
24 let exportName: string | undefined;
25
26 if (resolvedParentPath.isImportDefaultSpecifier()) {
27 exportName = 'default';
28 } else {
29 const imported = resolvedParentPath.get('imported');
30
31 if (imported.isStringLiteral()) {
32 exportName = imported.node.value;
33 } else if (imported.isIdentifier()) {
34 exportName = imported.node.name;
35 }
36 }
37
38 if (!exportName) {
39 throw new Error('Could not detect export name');
40 }
41
42 const importedPath = resolvedParentPath.hub.import(
43 resolvedParentPath.parentPath as NodePath<ImportDeclaration>,
44 exportName,
45 );
46
47 if (importedPath) {
48 return resolveToValue(importedPath);
49 }
50 }
51
52 return resolveToValue(resolvedParentPath);
53 }
54
55 return null;
56}
57
58interface TraverseState {
59 readonly idPath: NodePath<Identifier>;

Callers 1

resolveToValueFunction · 0.85

Calls 3

resolveToValueFunction · 0.85
getMethod · 0.80
importMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…