MCPcopy Index your code
hub / github.com/reactjs/react-docgen / resolveToModule

Function resolveToModule

packages/react-docgen/src/utils/resolveToModule.ts:11–44  ·  view source on GitHub ↗
(path: NodePath)

Source from the content-addressed store, hash-verified

9 * was imported.
10 */
11export default function resolveToModule(path: NodePath): string | null {
12 if (path.isVariableDeclarator()) {
13 if (path.node.init) {
14 return resolveToModule(path.get('init') as NodePath<Expression>);
15 }
16 } else if (path.isCallExpression()) {
17 const callee = path.get('callee');
18
19 if (callee.isIdentifier({ name: 'require' })) {
20 return (path.node.arguments[0] as StringLiteral).value;
21 }
22
23 return resolveToModule(callee);
24 } else if (path.isIdentifier() || path.isJSXIdentifier()) {
25 const valuePath = resolveToValue(path);
26
27 if (valuePath !== path) {
28 return resolveToModule(valuePath);
29 }
30 if (path.parentPath.isObjectProperty()) {
31 return resolveToModule(path.parentPath);
32 }
33 } else if (path.isObjectProperty() || path.isObjectPattern()) {
34 return resolveToModule(path.parentPath);
35 } else if (path.parentPath?.isImportDeclaration()) {
36 return path.parentPath.node.source.value;
37 } else if (path.isMemberExpression()) {
38 path = getMemberExpressionRoot(path);
39
40 return resolveToModule(path);
41 }
42
43 return null;
44}

Callers 6

isReactComponentClassFunction · 0.85
isReactBuiltinReferenceFunction · 0.85
amendComposesFunction · 0.85
isPropTypesExpressionFunction · 0.85

Calls 3

resolveToValueFunction · 0.85
getMemberExpressionRootFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected