@@ -725,49 +725,69 @@ module.exports = {
725
725
}
726
726
727
727
/**
728
- * Marks all props found inside IntersectionTypeAnnotation as declared.
729
- * Since InterSectionTypeAnnotations can be nested, this handles recursively.
728
+ * Marks all props found inside ObjectTypeAnnotaiton as declared.
730
729
*
731
- * Modifies the declaredPropTypes object
730
+ * Modifies the declaredProperties object
732
731
* @param {ASTNode } propTypes
733
732
* @param {Object } declaredPropTypes
734
733
* @returns {Boolean } True if propTypes should be ignored (e.g. when a type can't be resolved, when it is imported)
735
734
*/
736
- function declarePropTypesForIntersectionTypeAnnotation ( propTypes , declaredPropTypes ) {
735
+ function declarePropTypesForObjectTypeAnnotation ( propTypes , declaredPropTypes ) {
737
736
let ignorePropsValidation = false ;
738
737
739
- propTypes . types . forEach ( annotation => {
740
- const typeNode = typeScope ( annotation . id . name ) ;
741
-
742
- if ( ! typeNode ) {
738
+ iterateProperties ( propTypes . properties , ( key , value ) => {
739
+ if ( ! value ) {
743
740
ignorePropsValidation = true ;
744
741
return ;
745
742
}
746
743
747
- if ( typeNode . type === 'IntersectionTypeAnnotation' ) {
748
- ignorePropsValidation = declarePropTypesForIntersectionTypeAnnotation ( typeNode , declaredPropTypes ) ;
749
- } else {
750
- iterateProperties ( typeNode . properties , ( key , value ) => {
751
- if ( ! value ) {
752
- ignorePropsValidation = true ;
753
- return ;
754
- }
755
-
756
- let types = buildTypeAnnotationDeclarationTypes ( value , key ) ;
757
- if ( types === true ) {
758
- types = { } ;
759
- }
760
- types . fullName = key ;
761
- types . name = key ;
762
- types . node = value ;
763
- declaredPropTypes . push ( types ) ;
764
- } ) ;
744
+ let types = buildTypeAnnotationDeclarationTypes ( value , key ) ;
745
+ if ( types === true ) {
746
+ types = { } ;
765
747
}
748
+ types . fullName = key ;
749
+ types . name = key ;
750
+ types . node = value ;
751
+ declaredPropTypes . push ( types ) ;
766
752
} ) ;
767
753
768
754
return ignorePropsValidation ;
769
755
}
770
756
757
+ /**
758
+ * Marks all props found inside IntersectionTypeAnnotation as declared.
759
+ * Since InterSectionTypeAnnotations can be nested, this handles recursively.
760
+ *
761
+ * Modifies the declaredPropTypes object
762
+ * @param {ASTNode } propTypes
763
+ * @param {Object } declaredPropTypes
764
+ * @returns {Boolean } True if propTypes should be ignored (e.g. when a type can't be resolved, when it is imported)
765
+ */
766
+ function declarePropTypesForIntersectionTypeAnnotation ( propTypes , declaredPropTypes ) {
767
+ return propTypes . types . reduce ( ( ignorePropsValidation , annotation ) => {
768
+ // If we already decided to skip props validation then we don't have to continue processing anything else
769
+ if ( ignorePropsValidation ) {
770
+ return ignorePropsValidation ;
771
+ }
772
+
773
+ if ( annotation . type === 'ObjectTypeAnnotation' ) {
774
+ ignorePropsValidation = declarePropTypesForObjectTypeAnnotation ( annotation , declaredPropTypes ) ;
775
+ } else {
776
+ const typeNode = typeScope ( annotation . id . name ) ;
777
+
778
+ if ( ! typeNode ) {
779
+ ignorePropsValidation = true ;
780
+ } else if ( typeNode . type === 'IntersectionTypeAnnotation' ) {
781
+ ignorePropsValidation = declarePropTypesForIntersectionTypeAnnotation ( typeNode , declaredPropTypes ) ;
782
+ } else {
783
+ ignorePropsValidation = declarePropTypesForObjectTypeAnnotation ( typeNode , declaredPropTypes ) ;
784
+ }
785
+ }
786
+
787
+ return ignorePropsValidation ;
788
+ } , false ) ;
789
+ }
790
+
771
791
/**
772
792
* Mark a prop type as declared
773
793
* @param {ASTNode } node The AST node being checked.
@@ -780,20 +800,7 @@ module.exports = {
780
800
781
801
switch ( propTypes && propTypes . type ) {
782
802
case 'ObjectTypeAnnotation' :
783
- iterateProperties ( propTypes . properties , ( key , value ) => {
784
- if ( ! value ) {
785
- ignorePropsValidation = true ;
786
- return ;
787
- }
788
- let types = buildTypeAnnotationDeclarationTypes ( value , key ) ;
789
- if ( types === true ) {
790
- types = { } ;
791
- }
792
- types . fullName = key ;
793
- types . name = key ;
794
- types . node = value ;
795
- declaredPropTypes . push ( types ) ;
796
- } ) ;
803
+ ignorePropsValidation = declarePropTypesForObjectTypeAnnotation ( propTypes , declaredPropTypes ) ;
797
804
break ;
798
805
case 'ObjectExpression' :
799
806
iterateProperties ( propTypes . properties , ( key , value ) => {
0 commit comments