(path: NodePath)
| 9 | * was imported. |
| 10 | */ |
| 11 | export 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 | } |
no test coverage detected