@@ -710,6 +710,14 @@ module.exports = {
710
710
} ) ;
711
711
}
712
712
713
+ /**
714
+ * Marks all props found inside ObjectTypeAnnotaiton as declared.
715
+ *
716
+ * Modifies the declaredProperties object
717
+ * @param {ASTNode } propTypes
718
+ * @param {Object } declaredPropTypes
719
+ * @returns {Boolean } True if propTypes should be ignored (e.g. when a type can't be resolved, when it is imported)
720
+ */
713
721
function declarePropTypesForObjectTypeAnnotation ( propTypes , declaredPropTypes ) {
714
722
let ignorePropsValidation = false ;
715
723
@@ -734,33 +742,31 @@ module.exports = {
734
742
* @returns {Boolean } True if propTypes should be ignored (e.g. when a type can't be resolved, when it is imported)
735
743
*/
736
744
function declarePropTypesForIntersectionTypeAnnotation ( propTypes , declaredPropTypes ) {
737
- let ignorePropsValidation = false ;
745
+ return propTypes . types . reduce ( ( ignorePropsValidation , annotation ) => {
746
+ // If we already decided to skip props validation then we don't have to continue processing anything else
747
+ if ( ignorePropsValidation ) {
748
+ return ignorePropsValidation ;
749
+ }
738
750
739
- propTypes . types . forEach ( annotation => {
740
751
if ( annotation . type === 'ObjectTypeAnnotation' ) {
741
752
ignorePropsValidation = declarePropTypesForObjectTypeAnnotation ( annotation , declaredPropTypes ) ;
742
753
} else {
743
754
const typeNode = typeScope ( annotation . id . name ) ;
755
+
744
756
if ( ! typeNode ) {
745
757
ignorePropsValidation = true ;
746
- return ;
747
- }
748
-
749
- if ( typeNode . type === 'IntersectionTypeAnnotation' ) {
758
+ } else if ( typeNode . type === 'IntersectionTypeAnnotation' ) {
750
759
ignorePropsValidation = declarePropTypesForIntersectionTypeAnnotation ( typeNode , declaredPropTypes ) ;
751
760
} else {
752
- iterateProperties ( typeNode . properties , ( key , value ) => {
753
- if ( ! value ) {
754
- ignorePropsValidation = true ;
755
- return ;
756
- }
757
- declaredPropTypes [ key ] = buildTypeAnnotationDeclarationTypes ( value ) ;
758
- } ) ;
761
+ ignorePropsValidation = declarePropTypesForObjectTypeAnnotation ( typeNode , declaredPropTypes ) ;
759
762
}
760
763
}
761
- } ) ;
762
764
763
- return ignorePropsValidation ;
765
+ // Return early if we have to ignore props validation. No point to continue processing.
766
+ if ( ignorePropsValidation ) {
767
+ return ignorePropsValidation ;
768
+ }
769
+ } , false ) ;
764
770
}
765
771
766
772
/**
0 commit comments