@@ -393,14 +393,22 @@ module.exports = Components.detect(function(context, components, utils) {
393
393
break ;
394
394
case 'VariableDeclarator' :
395
395
for ( var i = 0 , j = node . id . properties . length ; i < j ; i ++ ) {
396
- if (
397
- ( node . id . properties [ i ] . key . name !== 'props' && node . id . properties [ i ] . key . value !== 'props' ) ||
398
- node . id . properties [ i ] . value . type !== 'ObjectPattern'
399
- ) {
396
+ // let {props: {firstname}} = this
397
+ var thisDestructuring = (
398
+ ( node . id . properties [ i ] . key . name === 'props' || node . id . properties [ i ] . key . value === 'props' ) &&
399
+ node . id . properties [ i ] . value . type === 'ObjectPattern'
400
+ ) ;
401
+ // let {firstname} = props
402
+ var statelessDestructuring = node . init . name === 'props' && utils . getParentStatelessComponent ( ) ;
403
+
404
+ if ( thisDestructuring ) {
405
+ properties = node . id . properties [ i ] . value . properties ;
406
+ } else if ( statelessDestructuring ) {
407
+ properties = node . id . properties ;
408
+ } else {
400
409
continue ;
401
410
}
402
411
type = 'destructuring' ;
403
- properties = node . id . properties [ i ] . value . properties ;
404
412
break ;
405
413
}
406
414
break ;
@@ -550,7 +558,12 @@ module.exports = Components.detect(function(context, components, utils) {
550
558
} ,
551
559
552
560
VariableDeclarator : function ( node ) {
553
- if ( ! node . init || node . init . type !== 'ThisExpression' || node . id . type !== 'ObjectPattern' ) {
561
+ // let {props: {firstname}} = this
562
+ var thisDestructuring = node . init && node . init . type === 'ThisExpression' && node . id . type === 'ObjectPattern' ;
563
+ // let {firstname} = props
564
+ var statelessDestructuring = node . init && node . init . name === 'props' && utils . getParentStatelessComponent ( ) ;
565
+
566
+ if ( ! thisDestructuring && ! statelessDestructuring ) {
554
567
return ;
555
568
}
556
569
markPropTypesAsUsed ( node ) ;
0 commit comments