@@ -20,15 +20,17 @@ namespace ts.codefix {
20
20
}
21
21
22
22
function getInsertionForMemberSymbol ( symbol : Symbol , enclosingDeclaration : ClassLikeDeclaration , checker : TypeChecker , newlineChar : string ) : string {
23
- const name = symbol . getName ( ) ;
23
+ // const name = symbol.getName();
24
24
const type = checker . getTypeOfSymbolAtLocation ( symbol , enclosingDeclaration ) ;
25
25
const declarations = symbol . getDeclarations ( ) ;
26
26
if ( ! ( declarations && declarations . length ) ) {
27
27
return "" ;
28
28
}
29
- const node = declarations [ 0 ] ;
30
- const visibility = getVisibilityPrefix ( getModifierFlags ( node ) ) ;
31
- switch ( node . kind ) {
29
+
30
+ const declaration = declarations [ 0 ] as Declaration ;
31
+ const name = declaration . name . getText ( ) ;
32
+ const visibility = getVisibilityPrefix ( getModifierFlags ( declaration ) ) ;
33
+ switch ( declaration . kind ) {
32
34
case SyntaxKind . GetAccessor :
33
35
case SyntaxKind . SetAccessor :
34
36
case SyntaxKind . PropertySignature :
@@ -68,14 +70,15 @@ namespace ts.codefix {
68
70
bodySig = checker . getSignatureFromDeclaration ( declarations [ declarations . length - 1 ] as SignatureDeclaration ) ;
69
71
}
70
72
else {
71
- bodySig = createBodyDeclarationSignatureWithAnyTypes ( declarations as SignatureDeclaration [ ] , signatures , enclosingDeclaration , checker ) ;
73
+ Debug . assert ( declarations . length === signatures . length ) ;
74
+ bodySig = createBodySignatureWithAnyTypes ( signatures , enclosingDeclaration , checker ) ;
72
75
}
73
76
const sigString = checker . signatureToString ( bodySig , enclosingDeclaration , TypeFormatFlags . SuppressAnyReturnType , SignatureKind . Call ) ;
74
77
result += `${ visibility } ${ name } ${ sigString } ${ getMethodBodyStub ( newlineChar ) } ` ;
75
78
76
79
return result ;
77
80
case SyntaxKind . ComputedPropertyName :
78
- if ( hasDynamicName ( node ) ) {
81
+ if ( hasDynamicName ( declaration ) ) {
79
82
return "" ;
80
83
}
81
84
throw new Error ( "Not implemented, computed property name." ) ;
@@ -87,22 +90,25 @@ namespace ts.codefix {
87
90
}
88
91
}
89
92
90
- function createBodyDeclarationSignatureWithAnyTypes ( signatureDecls : SignatureDeclaration [ ] , signatures : Signature [ ] , enclosingDeclaration : ClassLikeDeclaration , checker : TypeChecker ) : Signature {
91
- Debug . assert ( signatureDecls . length === signatures . length ) ;
93
+ function createBodySignatureWithAnyTypes ( signatures : Signature [ ] , enclosingDeclaration : ClassLikeDeclaration , checker : TypeChecker ) : Signature {
92
94
93
95
const newSignatureDeclaration = createNode ( SyntaxKind . CallSignature ) as SignatureDeclaration ;
94
96
newSignatureDeclaration . parent = enclosingDeclaration ;
95
- newSignatureDeclaration . name = signatureDecls [ 0 ] . name ;
97
+ newSignatureDeclaration . name = signatures [ 0 ] . getDeclaration ( ) . name ;
96
98
97
- let maxArgs = - 1 , maxArgsIndex = 0 ;
99
+ let maxArgs = - 1 ;
98
100
let minArgumentCount = signatures [ 0 ] . minArgumentCount ;
99
101
let hasRestParameter = false ;
102
+ let allMaxArgsAreRest = true ;
100
103
for ( let i = 0 ; i < signatures . length ; i ++ ) {
101
104
const sig = signatures [ i ] ;
102
105
minArgumentCount = Math . min ( sig . minArgumentCount , minArgumentCount ) ;
103
106
if ( sig . parameters . length > maxArgs ) {
104
107
maxArgs = sig . parameters . length ;
105
- maxArgsIndex = i ;
108
+ allMaxArgsAreRest = sig . hasRestParameter ;
109
+ }
110
+ else if ( sig . parameters . length === maxArgs ) {
111
+ allMaxArgsAreRest = allMaxArgsAreRest && sig . hasRestParameter ;
106
112
}
107
113
hasRestParameter = hasRestParameter || sig . hasRestParameter ;
108
114
}
@@ -120,10 +126,6 @@ namespace ts.codefix {
120
126
if ( hasRestParameter ) {
121
127
lastParameter . dotDotDotToken = createToken ( SyntaxKind . DotDotDotToken ) ;
122
128
123
- let allMaxArgsAreRest = true ;
124
- for ( const sig of signatures ) {
125
- allMaxArgsAreRest = allMaxArgsAreRest && sig . parameters [ maxArgs - 1 ] && sig . hasRestParameter ;
126
- }
127
129
if ( ! allMaxArgsAreRest ) {
128
130
const newParameter = createParameterDeclaration ( maxArgs - 1 , minArgumentCount , newSignatureDeclaration ) ;
129
131
newSignatureDeclaration . parameters . push ( newParameter ) ;
@@ -137,13 +139,13 @@ namespace ts.codefix {
137
139
138
140
return checker . getSignatureFromDeclaration ( newSignatureDeclaration ) ;
139
141
140
- function createParameterDeclaration ( index : number , minArgCount : number , enclosingSignature : SignatureDeclaration ) : ParameterDeclaration {
142
+ function createParameterDeclaration ( index : number , minArgCount : number , enclosingSignatureDeclaration : SignatureDeclaration ) : ParameterDeclaration {
141
143
const newParameter = createNode ( SyntaxKind . Parameter ) as ParameterDeclaration ;
142
144
newParameter . symbol = checker . createSymbol ( SymbolFlags . FunctionScopedVariable , "arg" + index ) ;
143
145
newParameter . symbol . valueDeclaration = newParameter ;
144
146
newParameter . symbol . declarations = [ newParameter ] ;
145
147
newParameter . type = anyTypeNode ;
146
- newParameter . parent = enclosingSignature ;
148
+ newParameter . parent = enclosingSignatureDeclaration ;
147
149
if ( index >= minArgCount ) {
148
150
newParameter . questionToken = optionalToken ;
149
151
}
0 commit comments