@@ -484,14 +484,25 @@ module.exports = {
484
484
* Creates the representation of the React props type annotation for the component.
485
485
* The representation is used to verify nested used properties.
486
486
* @param {ASTNode } annotation Type annotation for the props class property.
487
+ * @param {Array } seen Keeps track of annotations we've already seen.
487
488
* @return {Object|Boolean } The representation of the declaration, true means
488
489
* the property is declared without the need for further analysis.
489
490
*/
490
- function buildTypeAnnotationDeclarationTypes ( annotation ) {
491
+ function buildTypeAnnotationDeclarationTypes ( annotation , seen ) {
492
+ if ( seen === void 0 ) {
493
+ // Keeps track of annotations we've already seen to
494
+ // prevent problems with cyclic types.
495
+ seen = [ ] ;
496
+ }
497
+ if ( seen . indexOf ( annotation ) > - 1 ) {
498
+ // this must be a recursive type annotation, just accept anything.
499
+ return true ;
500
+ }
501
+ seen . push ( annotation ) ;
491
502
switch ( annotation . type ) {
492
503
case 'GenericTypeAnnotation' :
493
504
if ( typeScope ( annotation . id . name ) ) {
494
- return buildTypeAnnotationDeclarationTypes ( typeScope ( annotation . id . name ) ) ;
505
+ return buildTypeAnnotationDeclarationTypes ( typeScope ( annotation . id . name ) , seen ) ;
495
506
}
496
507
return true ;
497
508
case 'ObjectTypeAnnotation' :
@@ -500,7 +511,7 @@ module.exports = {
500
511
children : { }
501
512
} ;
502
513
iterateProperties ( annotation . properties , function ( childKey , childValue ) {
503
- shapeTypeDefinition . children [ childKey ] = buildTypeAnnotationDeclarationTypes ( childValue ) ;
514
+ shapeTypeDefinition . children [ childKey ] = buildTypeAnnotationDeclarationTypes ( childValue , seen ) ;
504
515
} ) ;
505
516
return shapeTypeDefinition ;
506
517
case 'UnionTypeAnnotation' :
@@ -509,7 +520,7 @@ module.exports = {
509
520
children : [ ]
510
521
} ;
511
522
for ( var i = 0 , j = annotation . types . length ; i < j ; i ++ ) {
512
- var type = buildTypeAnnotationDeclarationTypes ( annotation . types [ i ] ) ;
523
+ var type = buildTypeAnnotationDeclarationTypes ( annotation . types [ i ] , seen ) ;
513
524
// keep only complex type
514
525
if ( type !== true ) {
515
526
if ( type . children === true ) {
@@ -530,7 +541,7 @@ module.exports = {
530
541
return {
531
542
type : 'object' ,
532
543
children : {
533
- __ANY_KEY__ : buildTypeAnnotationDeclarationTypes ( annotation . elementType )
544
+ __ANY_KEY__ : buildTypeAnnotationDeclarationTypes ( annotation . elementType , seen )
534
545
}
535
546
} ;
536
547
default :
0 commit comments