@@ -710,6 +710,20 @@ module.exports = {
710
710
} ) ;
711
711
}
712
712
713
+ function declarePropTypesForObjectTypeAnnotation ( propTypes , declaredPropTypes ) {
714
+ let ignorePropsValidation = false ;
715
+
716
+ iterateProperties ( propTypes . properties , ( key , value ) => {
717
+ if ( ! value ) {
718
+ ignorePropsValidation = true ;
719
+ return ;
720
+ }
721
+ declaredPropTypes [ key ] = buildTypeAnnotationDeclarationTypes ( value ) ;
722
+ } ) ;
723
+
724
+ return ignorePropsValidation ;
725
+ }
726
+
713
727
/**
714
728
* Marks all props found inside IntersectionTypeAnnotation as declared.
715
729
* Since InterSectionTypeAnnotations can be nested, this handles recursively.
@@ -723,22 +737,26 @@ module.exports = {
723
737
let ignorePropsValidation = false ;
724
738
725
739
propTypes . types . forEach ( annotation => {
726
- const typeNode = typeScope ( annotation . id . name ) ;
727
- if ( ! typeNode ) {
728
- ignorePropsValidation = true ;
729
- return ;
730
- }
731
-
732
- if ( typeNode . type === 'IntersectionTypeAnnotation' ) {
733
- ignorePropsValidation = declarePropTypesForIntersectionTypeAnnotation ( typeNode , declaredPropTypes ) ;
740
+ if ( annotation . type === 'ObjectTypeAnnotation' ) {
741
+ ignorePropsValidation = declarePropTypesForObjectTypeAnnotation ( annotation , declaredPropTypes ) ;
734
742
} else {
735
- iterateProperties ( typeNode . properties , ( key , value ) => {
736
- if ( ! value ) {
737
- ignorePropsValidation = true ;
738
- return ;
739
- }
740
- declaredPropTypes [ key ] = buildTypeAnnotationDeclarationTypes ( value ) ;
741
- } ) ;
743
+ const typeNode = typeScope ( annotation . id . name ) ;
744
+ if ( ! typeNode ) {
745
+ ignorePropsValidation = true ;
746
+ return ;
747
+ }
748
+
749
+ if ( typeNode . type === 'IntersectionTypeAnnotation' ) {
750
+ ignorePropsValidation = declarePropTypesForIntersectionTypeAnnotation ( typeNode , declaredPropTypes ) ;
751
+ } else {
752
+ iterateProperties ( typeNode . properties , ( key , value ) => {
753
+ if ( ! value ) {
754
+ ignorePropsValidation = true ;
755
+ return ;
756
+ }
757
+ declaredPropTypes [ key ] = buildTypeAnnotationDeclarationTypes ( value ) ;
758
+ } ) ;
759
+ }
742
760
}
743
761
} ) ;
744
762
@@ -761,13 +779,7 @@ module.exports = {
761
779
762
780
switch ( propTypes && propTypes . type ) {
763
781
case 'ObjectTypeAnnotation' :
764
- iterateProperties ( propTypes . properties , ( key , value ) => {
765
- if ( ! value ) {
766
- ignorePropsValidation = true ;
767
- return ;
768
- }
769
- declaredPropTypes [ key ] = buildTypeAnnotationDeclarationTypes ( value ) ;
770
- } ) ;
782
+ ignorePropsValidation = declarePropTypesForObjectTypeAnnotation ( propTypes , declaredPropTypes ) ;
771
783
break ;
772
784
case 'ObjectExpression' :
773
785
iterateProperties ( propTypes . properties , ( key , value ) => {
0 commit comments