@@ -710,6 +710,14 @@ module.exports = {
710710 } ) ;
711711 }
712712
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+ */
713721 function declarePropTypesForObjectTypeAnnotation ( propTypes , declaredPropTypes ) {
714722 let ignorePropsValidation = false ;
715723
@@ -734,33 +742,31 @@ module.exports = {
734742 * @returns {Boolean } True if propTypes should be ignored (e.g. when a type can't be resolved, when it is imported)
735743 */
736744 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+ }
738750
739- propTypes . types . forEach ( annotation => {
740751 if ( annotation . type === 'ObjectTypeAnnotation' ) {
741752 ignorePropsValidation = declarePropTypesForObjectTypeAnnotation ( annotation , declaredPropTypes ) ;
742753 } else {
743754 const typeNode = typeScope ( annotation . id . name ) ;
755+
744756 if ( ! typeNode ) {
745757 ignorePropsValidation = true ;
746- return ;
747- }
748-
749- if ( typeNode . type === 'IntersectionTypeAnnotation' ) {
758+ } else if ( typeNode . type === 'IntersectionTypeAnnotation' ) {
750759 ignorePropsValidation = declarePropTypesForIntersectionTypeAnnotation ( typeNode , declaredPropTypes ) ;
751760 } 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 ) ;
759762 }
760763 }
761- } ) ;
762764
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 ) ;
764770 }
765771
766772 /**
0 commit comments