@@ -52,17 +52,15 @@ function findScopePath(
52
52
let resultPath = paths [ 0 ] ;
53
53
const parentPath = resultPath . parent ;
54
54
55
+ // Namespace imports are handled separately, at the site of a member expression access
55
56
if (
56
57
resolveImports &&
57
58
( t . ImportDefaultSpecifier . check ( parentPath . node ) ||
58
- t . ImportSpecifier . check ( parentPath . node ) ||
59
- t . ImportNamespaceSpecifier . check ( parentPath . node ) )
59
+ t . ImportSpecifier . check ( parentPath . node ) )
60
60
) {
61
61
let exportName ;
62
62
if ( t . ImportDefaultSpecifier . check ( parentPath . node ) ) {
63
63
exportName = 'default' ;
64
- } else if ( t . ImportNamespaceSpecifier . check ( parentPath . node ) ) {
65
- exportName = '*' ;
66
64
} else {
67
65
exportName = parentPath . node . imported . name ;
68
66
}
@@ -150,8 +148,9 @@ export default function resolveToValue(
150
148
return resolveToValue ( path . get ( 'init' ) , resolveImports ) ;
151
149
}
152
150
} else if ( t . MemberExpression . check ( node ) ) {
153
- const resolved = resolveToValue (
154
- getMemberExpressionRoot ( path ) ,
151
+ const root = getMemberExpressionRoot ( path ) ;
152
+ let resolved = resolveToValue (
153
+ root ,
155
154
resolveImports ,
156
155
) ;
157
156
if ( t . ObjectExpression . check ( resolved . node ) ) {
@@ -169,6 +168,18 @@ export default function resolveToValue(
169
168
} else if ( isSupportedDefinitionType ( resolved ) ) {
170
169
const memberPath = getMemberValuePath ( resolved , path . node . property . name ) ;
171
170
return memberPath || path ;
171
+ } else if ( t . ImportDeclaration . check ( resolved . node ) ) {
172
+ // Handle references to namespace imports, e.g. import * as foo from 'bar'.
173
+ // Try to find a specifier that matches the root of the member expression, and
174
+ // find the export that matches the property name.
175
+ for ( let specifier of resolved . node . specifiers ) {
176
+ if ( t . ImportNamespaceSpecifier . check ( specifier ) && specifier . local . name === root . node . name ) {
177
+ const resolvedPath = resolveImportedValue ( resolved , root . parentPath . node . property . name ) ;
178
+ if ( resolvedPath ) {
179
+ return resolveToValue ( resolvedPath , resolveImports ) ;
180
+ }
181
+ }
182
+ }
172
183
}
173
184
} else if (
174
185
t . ImportDefaultSpecifier . check ( node ) ||
0 commit comments