11import ts from 'typescript' ;
2+ import { GetTsAutoMockOverloadOptions , TsAutoMockOverloadOptions } from '../../../options/overload' ;
23import { MethodSignature , TypescriptCreator } from '../../helper/creator' ;
34import { MockDefiner } from '../../mockDefiner/mockDefiner' ;
45import { ModuleName } from '../../mockDefiner/modules/moduleName' ;
@@ -8,8 +9,11 @@ import { TypescriptHelper } from '../helper/helper';
89
910export function GetMethodDescriptor ( _propertyName : ts . PropertyName , methodSignatures : MethodSignature [ ] , scope : Scope ) : ts . CallExpression {
1011 const providerGetMethod : ts . PropertyAccessExpression = CreateProviderGetMethod ( ) ;
12+ const transformOverloadsOption : TsAutoMockOverloadOptions = GetTsAutoMockOverloadOptions ( ) ;
1113
12- const signatureWithMostParameters : MethodSignature = methodSignatures . reduce (
14+ const signatures : MethodSignature [ ] = methodSignatures . filter ( ( _ : unknown , notFirst : number ) => transformOverloadsOption || ! notFirst ) ;
15+
16+ const signatureWithMostParameters : MethodSignature = signatures . reduce (
1317 ( acc : MethodSignature , signature : MethodSignature ) => {
1418 const longestParametersLength : number = ( acc . parameters || [ ] ) . length ;
1519 const parametersLength : number = ( signature . parameters || [ ] ) . length ;
@@ -21,7 +25,7 @@ export function GetMethodDescriptor(_propertyName: ts.PropertyName, methodSignat
2125 const declarationVariableMap : Map < ts . TypeNode , ts . Identifier > = new Map < ts . TypeNode , ts . Identifier > ( ) ;
2226
2327 let i : number = 0 ;
24- const declarationVariables : ts . VariableDeclaration [ ] = methodSignatures . reduce (
28+ const declarationVariables : ts . VariableDeclaration [ ] = signatures . reduce (
2529 ( variables : ts . VariableDeclaration [ ] , { parameters } : MethodSignature ) => {
2630 for ( const parameter of parameters ) {
2731 if ( declarationVariableMap . has ( parameter . type ) ) {
@@ -54,7 +58,7 @@ export function GetMethodDescriptor(_propertyName: ts.PropertyName, methodSignat
5458 statements . push ( TypescriptCreator . createVariableStatement ( declarationVariables ) ) ;
5559 }
5660
57- statements . push ( ResolveSignatureElseBranch ( declarationVariableMap , methodSignatures , signatureWithMostParameters , scope ) ) ;
61+ statements . push ( ResolveSignatureElseBranch ( declarationVariableMap , signatures , signatureWithMostParameters , scope ) ) ;
5862
5963 const block : ts . Block = ts . createBlock ( statements , true ) ;
6064
0 commit comments