@@ -42,13 +42,11 @@ import { DeclarationMetadata } from '../collector/DeclarationMetadata';
4242
4343export class ApiModelGenerator {
4444 private readonly _collector : Collector ;
45- private readonly _cachedOverloadIndexesByDeclaration : Map < AstDeclaration , number > ;
4645 private readonly _apiModel : ApiModel ;
4746 private readonly _referenceGenerator : DeclarationReferenceGenerator ;
4847
4948 public constructor ( collector : Collector ) {
5049 this . _collector = collector ;
51- this . _cachedOverloadIndexesByDeclaration = new Map < AstDeclaration , number > ( ) ;
5250 this . _apiModel = new ApiModel ( ) ;
5351 this . _referenceGenerator = new DeclarationReferenceGenerator (
5452 collector . packageJsonLookup ,
@@ -193,7 +191,7 @@ export class ApiModelGenerator {
193191 private _processApiCallSignature ( astDeclaration : AstDeclaration , exportedName : string | undefined ,
194192 parentApiItem : ApiItemContainerMixin ) : void {
195193
196- const overloadIndex : number = this . _getOverloadIndex ( astDeclaration ) ;
194+ const overloadIndex : number = this . _collector . getOverloadIndex ( astDeclaration ) ;
197195 const containerKey : string = ApiCallSignature . getContainerKey ( overloadIndex ) ;
198196
199197 let apiCallSignature : ApiCallSignature | undefined = parentApiItem . tryGetMemberByKey ( containerKey ) as
@@ -234,7 +232,7 @@ export class ApiModelGenerator {
234232 private _processApiConstructor ( astDeclaration : AstDeclaration , exportedName : string | undefined ,
235233 parentApiItem : ApiItemContainerMixin ) : void {
236234
237- const overloadIndex : number = this . _getOverloadIndex ( astDeclaration ) ;
235+ const overloadIndex : number = this . _collector . getOverloadIndex ( astDeclaration ) ;
238236 const containerKey : string = ApiConstructor . getContainerKey ( overloadIndex ) ;
239237
240238 let apiConstructor : ApiConstructor | undefined = parentApiItem . tryGetMemberByKey ( containerKey ) as ApiConstructor ;
@@ -322,7 +320,7 @@ export class ApiModelGenerator {
322320 private _processApiConstructSignature ( astDeclaration : AstDeclaration , exportedName : string | undefined ,
323321 parentApiItem : ApiItemContainerMixin ) : void {
324322
325- const overloadIndex : number = this . _getOverloadIndex ( astDeclaration ) ;
323+ const overloadIndex : number = this . _collector . getOverloadIndex ( astDeclaration ) ;
326324 const containerKey : string = ApiConstructSignature . getContainerKey ( overloadIndex ) ;
327325
328326 let apiConstructSignature : ApiConstructSignature | undefined = parentApiItem . tryGetMemberByKey ( containerKey ) as
@@ -420,7 +418,7 @@ export class ApiModelGenerator {
420418
421419 const name : string = exportedName ? exportedName : astDeclaration . astSymbol . localName ;
422420
423- const overloadIndex : number = this . _getOverloadIndex ( astDeclaration ) ;
421+ const overloadIndex : number = this . _collector . getOverloadIndex ( astDeclaration ) ;
424422 const containerKey : string = ApiFunction . getContainerKey ( name , overloadIndex ) ;
425423
426424 let apiFunction : ApiFunction | undefined = parentApiItem . tryGetMemberByKey ( containerKey ) as
@@ -466,7 +464,7 @@ export class ApiModelGenerator {
466464 private _processApiIndexSignature ( astDeclaration : AstDeclaration , exportedName : string | undefined ,
467465 parentApiItem : ApiItemContainerMixin ) : void {
468466
469- const overloadIndex : number = this . _getOverloadIndex ( astDeclaration ) ;
467+ const overloadIndex : number = this . _collector . getOverloadIndex ( astDeclaration ) ;
470468 const containerKey : string = ApiIndexSignature . getContainerKey ( overloadIndex ) ;
471469
472470 let apiIndexSignature : ApiIndexSignature | undefined = parentApiItem . tryGetMemberByKey ( containerKey ) as
@@ -554,7 +552,7 @@ export class ApiModelGenerator {
554552 const name : string = exportedName ? exportedName : astDeclaration . astSymbol . localName ;
555553
556554 const isStatic : boolean = ( astDeclaration . modifierFlags & ts . ModifierFlags . Static ) !== 0 ;
557- const overloadIndex : number = this . _getOverloadIndex ( astDeclaration ) ;
555+ const overloadIndex : number = this . _collector . getOverloadIndex ( astDeclaration ) ;
558556 const containerKey : string = ApiMethod . getContainerKey ( name , isStatic , overloadIndex ) ;
559557
560558 let apiMethod : ApiMethod | undefined = parentApiItem . tryGetMemberByKey ( containerKey ) as ApiMethod ;
@@ -601,7 +599,7 @@ export class ApiModelGenerator {
601599
602600 const name : string = exportedName ? exportedName : astDeclaration . astSymbol . localName ;
603601
604- const overloadIndex : number = this . _getOverloadIndex ( astDeclaration ) ;
602+ const overloadIndex : number = this . _collector . getOverloadIndex ( astDeclaration ) ;
605603 const containerKey : string = ApiMethodSignature . getContainerKey ( name , overloadIndex ) ;
606604
607605 let apiMethodSignature : ApiMethodSignature | undefined = parentApiItem . tryGetMemberByKey ( containerKey ) as
@@ -857,34 +855,4 @@ export class ApiModelGenerator {
857855 }
858856 return parameters ;
859857 }
860-
861- private _getOverloadIndex ( astDeclaration : AstDeclaration ) : number {
862- const allDeclarations : ReadonlyArray < AstDeclaration > = astDeclaration . astSymbol . astDeclarations ;
863- if ( allDeclarations . length === 1 ) {
864- return 1 ; // trivial case
865- }
866-
867- let overloadIndex : number | undefined = this . _cachedOverloadIndexesByDeclaration . get ( astDeclaration ) ;
868-
869- if ( overloadIndex === undefined ) {
870- // TSDoc index selectors are positive integers counting from 1
871- let nextIndex : number = 1 ;
872- for ( const other of allDeclarations ) {
873- // Filter out other declarations that are not overloads. For example, an overloaded function can also
874- // be a namespace.
875- if ( other . declaration . kind === astDeclaration . declaration . kind ) {
876- this . _cachedOverloadIndexesByDeclaration . set ( other , nextIndex ) ;
877- ++ nextIndex ;
878- }
879- }
880- overloadIndex = this . _cachedOverloadIndexesByDeclaration . get ( astDeclaration ) ;
881- }
882-
883- if ( overloadIndex === undefined ) {
884- // This should never happen
885- throw new Error ( 'Error calculating overload index for declaration' ) ;
886- }
887-
888- return overloadIndex ;
889- }
890858}
0 commit comments