@@ -178,10 +178,11 @@ namespace ts.codefix {
178
178
// if the identifier refers to a function we want to add the new synthesized variable for the declaration (ex. blob in let blob = res(arg))
179
179
// Note - the choice of the last call signature is arbitrary
180
180
if ( lastCallSignature && lastCallSignature . parameters . length && ! synthNamesMap . has ( symbolIdString ) ) {
181
- const name = lastCallSignature . parameters [ 0 ] . name ;
182
- const synthName = getNewNameIfConflict ( createIdentifier ( name ) , allVarNames ) ;
181
+ const firstParameter = lastCallSignature . parameters [ 0 ] ;
182
+ const ident = isParameter ( firstParameter . valueDeclaration ) && tryCast ( firstParameter . valueDeclaration . name , isIdentifier ) || createOptimisticUniqueName ( "result" ) ;
183
+ const synthName = getNewNameIfConflict ( ident , allVarNames ) ;
183
184
synthNamesMap . set ( symbolIdString , synthName ) ;
184
- allVarNames . push ( { identifier : synthName . identifier , symbol, originalName : name } ) ;
185
+ allVarNames . push ( { identifier : synthName . identifier , symbol, originalName : ident . text } ) ;
185
186
}
186
187
// we only care about identifiers that are parameters and declarations (don't care about other uses)
187
188
else if ( node . parent && ( isParameter ( node . parent ) || isVariableDeclaration ( node . parent ) ) ) {
@@ -449,7 +450,7 @@ namespace ts.codefix {
449
450
450
451
function getLastCallSignature ( type : Type , checker : TypeChecker ) : Signature | undefined {
451
452
const callSignatures = checker . getSignaturesOfType ( type , SignatureKind . Call ) ;
452
- return callSignatures && callSignatures [ callSignatures . length - 1 ] ;
453
+ return lastOrUndefined ( callSignatures ) ;
453
454
}
454
455
455
456
0 commit comments