@@ -90,7 +90,7 @@ export interface WalkState extends WalkContext {
9090 ) => void ;
9191 getFix : ( start : number , end : number , flags ?: number ) => Fix ;
9292 getTypeFix : ( start : number , end : number ) => Fix ;
93- collectRefsInType : ( node : any , exportName : string , signatureOnly : boolean ) => void ;
93+ collectRefsInType : ( node : any , exportName : string , signatureOnly : boolean , inMember ?: boolean ) => void ;
9494 addRefInExport : ( name : string , exportName : string ) => void ;
9595 isInNamespace : ( node : Span ) => boolean ;
9696}
@@ -142,14 +142,24 @@ const _addExport = (
142142 }
143143} ;
144144
145- const _collectRefsInType = ( node : any , exportName : string , signatureOnly : boolean ) : void => {
145+ const MEMBER_CONTAINERS = new Set ( [
146+ 'TSPropertySignature' ,
147+ 'TSMethodSignature' ,
148+ 'TSIndexSignature' ,
149+ 'TSCallSignatureDeclaration' ,
150+ 'TSConstructSignatureDeclaration' ,
151+ ] ) ;
152+
153+ const _collectRefsInType = ( node : any , exportName : string , signatureOnly : boolean , inMember = false ) : void => {
146154 if ( ! node || typeof node !== 'object' ) return ;
147155 if ( node . type === 'TSTypeQuery' ) {
148- const name = node . exprName . type === 'Identifier' ? node . exprName . name : undefined ;
149- if ( name ) {
150- const refs = state . referencedInExport . get ( name ) ;
151- if ( refs ) refs . add ( exportName ) ;
152- else state . referencedInExport . set ( name , new Set ( [ exportName ] ) ) ;
156+ if ( inMember ) {
157+ const name = node . exprName . type === 'Identifier' ? node . exprName . name : undefined ;
158+ if ( name ) {
159+ const refs = state . referencedInExport . get ( name ) ;
160+ if ( refs ) refs . add ( exportName ) ;
161+ else state . referencedInExport . set ( name , new Set ( [ exportName ] ) ) ;
162+ }
153163 }
154164 return ;
155165 }
@@ -160,15 +170,17 @@ const _collectRefsInType = (node: any, exportName: string, signatureOnly: boolea
160170 if ( refs ) refs . add ( exportName ) ;
161171 else state . referencedInExport . set ( name , new Set ( [ exportName ] ) ) ;
162172 }
173+ const nextInMember = inMember || MEMBER_CONTAINERS . has ( node . type ) ;
163174 for ( const key in node ) {
164175 if ( key === 'type' || key === 'parent' ) continue ;
165176 const val = node [ key ] ;
166177 if ( Array . isArray ( val ) ) {
167178 for ( const item of val ) {
168- if ( item && typeof item === 'object' && item . type ) _collectRefsInType ( item , exportName , signatureOnly ) ;
179+ if ( item && typeof item === 'object' && item . type )
180+ _collectRefsInType ( item , exportName , signatureOnly , nextInMember ) ;
169181 }
170182 } else if ( val && typeof val === 'object' && val . type ) {
171- _collectRefsInType ( val , exportName , signatureOnly ) ;
183+ _collectRefsInType ( val , exportName , signatureOnly , nextInMember ) ;
172184 }
173185 }
174186} ;
0 commit comments