@@ -393,14 +393,22 @@ module.exports = Components.detect(function(context, components, utils) {
393393 break ;
394394 case 'VariableDeclarator' :
395395 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 {
400409 continue ;
401410 }
402411 type = 'destructuring' ;
403- properties = node . id . properties [ i ] . value . properties ;
404412 break ;
405413 }
406414 break ;
@@ -550,7 +558,12 @@ module.exports = Components.detect(function(context, components, utils) {
550558 } ,
551559
552560 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 ) {
554567 return ;
555568 }
556569 markPropTypesAsUsed ( node ) ;
0 commit comments