( bindingIdentifiers: Array<NodePath<Identifier>> | undefined, )
| 12 | import getNameOrValue from './getNameOrValue.js'; |
| 13 | |
| 14 | function 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 | |
| 58 | interface TraverseState { |
| 59 | readonly idPath: NodePath<Identifier>; |
no test coverage detected
searching dependent graphs…