@@ -332,6 +332,8 @@ function componentRule(rule, context) {
332332 var j ;
333333 var k ;
334334 var l ;
335+ var componentName ;
336+ var componentNode ;
335337 // Get the component path
336338 var componentPath = [ ] ;
337339 while ( node ) {
@@ -344,6 +346,7 @@ function componentRule(rule, context) {
344346 node = node . object ;
345347 }
346348 componentPath . reverse ( ) ;
349+ componentName = componentPath . slice ( 0 , componentPath . length - 1 ) . join ( '.' ) ;
347350
348351 // Find the variable in the current scope
349352 var variableName = componentPath . shift ( ) ;
@@ -362,7 +365,31 @@ function componentRule(rule, context) {
362365 return null ;
363366 }
364367
365- // Find the variable declaration
368+ // Try to find the component using variable references
369+ var refs = variableInScope . references ;
370+ var refId ;
371+ for ( i = 0 , j = refs . length ; i < j ; i ++ ) {
372+ refId = refs [ i ] . identifier ;
373+ if ( refId . parent && refId . parent . type === 'MemberExpression' ) {
374+ refId = refId . parent ;
375+ }
376+ if ( sourceCode . getText ( refId ) !== componentName ) {
377+ continue ;
378+ }
379+ if ( refId . type === 'MemberExpression' ) {
380+ componentNode = refId . parent . right ;
381+ } else if ( refId . parent && refId . parent . type === 'VariableDeclarator' ) {
382+ componentNode = refId . parent . init ;
383+ }
384+ break ;
385+ }
386+
387+ if ( componentNode ) {
388+ // Return the component
389+ return components . add ( componentNode , 1 ) ;
390+ }
391+
392+ // Try to find the component using variable declarations
366393 var defInScope ;
367394 var defs = variableInScope . defs ;
368395 for ( i = 0 , j = defs . length ; i < j ; i ++ ) {
@@ -374,27 +401,27 @@ function componentRule(rule, context) {
374401 if ( ! defInScope || ! defInScope . node ) {
375402 return null ;
376403 }
377- node = defInScope . node . init || defInScope . node ;
404+ componentNode = defInScope . node . init || defInScope . node ;
378405
379406 // Traverse the node properties to the component declaration
380407 for ( i = 0 , j = componentPath . length ; i < j ; i ++ ) {
381- if ( ! node . properties ) {
408+ if ( ! componentNode . properties ) {
382409 continue ;
383410 }
384- for ( k = 0 , l = node . properties . length ; k < l ; k ++ ) {
385- if ( node . properties [ k ] . key . name === componentPath [ i ] ) {
386- node = node . properties [ k ] ;
411+ for ( k = 0 , l = componentNode . properties . length ; k < l ; k ++ ) {
412+ if ( componentNode . properties [ k ] . key . name === componentPath [ i ] ) {
413+ componentNode = componentNode . properties [ k ] ;
387414 break ;
388415 }
389416 }
390- if ( ! node || ! node . value ) {
417+ if ( ! componentNode || ! componentNode . value ) {
391418 return null ;
392419 }
393- node = node . value ;
420+ componentNode = componentNode . value ;
394421 }
395422
396423 // Return the component
397- return components . add ( node , 1 ) ;
424+ return components . add ( componentNode , 1 ) ;
398425 }
399426 } ;
400427
0 commit comments