@@ -725,49 +725,69 @@ module.exports = {
725725 }
726726
727727 /**
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.
730729 *
731- * Modifies the declaredPropTypes object
730+ * Modifies the declaredProperties object
732731 * @param {ASTNode } propTypes
733732 * @param {Object } declaredPropTypes
734733 * @returns {Boolean } True if propTypes should be ignored (e.g. when a type can't be resolved, when it is imported)
735734 */
736- function declarePropTypesForIntersectionTypeAnnotation ( propTypes , declaredPropTypes ) {
735+ function declarePropTypesForObjectTypeAnnotation ( propTypes , declaredPropTypes ) {
737736 let ignorePropsValidation = false ;
738737
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 ) {
743740 ignorePropsValidation = true ;
744741 return ;
745742 }
746743
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 = { } ;
765747 }
748+ types . fullName = key ;
749+ types . name = key ;
750+ types . node = value ;
751+ declaredPropTypes . push ( types ) ;
766752 } ) ;
767753
768754 return ignorePropsValidation ;
769755 }
770756
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+
771791 /**
772792 * Mark a prop type as declared
773793 * @param {ASTNode } node The AST node being checked.
@@ -780,20 +800,7 @@ module.exports = {
780800
781801 switch ( propTypes && propTypes . type ) {
782802 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 ) ;
797804 break ;
798805 case 'ObjectExpression' :
799806 iterateProperties ( propTypes . properties , ( key , value ) => {
0 commit comments