@@ -158,7 +158,11 @@ export function applyToTypeProperties(
158158 path : NodePath ,
159159 callback : ( propertyPath : NodePath , params : TypeParameters | null ) => void ,
160160 typeParams : TypeParameters | null ,
161+ visited = new WeakSet < object > ( ) ,
161162) : void {
163+ if ( visited . has ( path . node ) ) return ;
164+ visited . add ( path . node ) ;
165+
162166 if ( path . isObjectTypeAnnotation ( ) ) {
163167 path
164168 . get ( 'properties' )
@@ -168,14 +172,14 @@ export function applyToTypeProperties(
168172 . get ( 'members' )
169173 . forEach ( ( propertyPath ) => callback ( propertyPath , typeParams ) ) ;
170174 } else if ( path . isInterfaceDeclaration ( ) ) {
171- applyExtends ( documentation , path , callback , typeParams ) ;
175+ applyExtends ( documentation , path , callback , typeParams , visited ) ;
172176
173177 path
174178 . get ( 'body' )
175179 . get ( 'properties' )
176180 . forEach ( ( propertyPath ) => callback ( propertyPath , typeParams ) ) ;
177181 } else if ( path . isTSInterfaceDeclaration ( ) ) {
178- applyExtends ( documentation , path , callback , typeParams ) ;
182+ applyExtends ( documentation , path , callback , typeParams , visited ) ;
179183
180184 path
181185 . get ( 'body' )
@@ -187,15 +191,27 @@ export function applyToTypeProperties(
187191 ) {
188192 ( path . get ( 'types' ) as Array < NodePath < FlowType | TSType > > ) . forEach (
189193 ( typesPath ) =>
190- applyToTypeProperties ( documentation , typesPath , callback , typeParams ) ,
194+ applyToTypeProperties (
195+ documentation ,
196+ typesPath ,
197+ callback ,
198+ typeParams ,
199+ visited ,
200+ ) ,
191201 ) ;
192202 } else if ( ! path . isUnionTypeAnnotation ( ) ) {
193203 // The react-docgen output format does not currently allow
194204 // for the expression of union types
195205 const typePath = resolveGenericTypeAnnotation ( path ) ;
196206
197207 if ( typePath ) {
198- applyToTypeProperties ( documentation , typePath , callback , typeParams ) ;
208+ applyToTypeProperties (
209+ documentation ,
210+ typePath ,
211+ callback ,
212+ typeParams ,
213+ visited ,
214+ ) ;
199215 }
200216 }
201217}
@@ -205,6 +221,7 @@ function applyExtends(
205221 path : NodePath < InterfaceDeclaration | TSInterfaceDeclaration > ,
206222 callback : ( propertyPath : NodePath , params : TypeParameters | null ) => void ,
207223 typeParams : TypeParameters | null ,
224+ visited : WeakSet < object > ,
208225) : void {
209226 const classExtends = path . get ( 'extends' ) ;
210227
@@ -238,6 +255,7 @@ function applyExtends(
238255 resolvedPath ,
239256 callback ,
240257 typeParams ,
258+ visited ,
241259 ) ;
242260 } else {
243261 const idPath = getTypeIdentifier ( extendsPath ) ;
0 commit comments