@@ -199,7 +199,26 @@ namespace ts.codefix {
199
199
}
200
200
} ) ;
201
201
202
- return getSynthesizedDeepCloneWithRenames ( nodeToRename , /*includeTrivia*/ true , identsToRenameMap , checker ) ;
202
+ return getSynthesizedDeepCloneWithReplacements ( nodeToRename , /*includeTrivia*/ true , original => {
203
+ if ( isBindingElement ( original ) && isIdentifier ( original . name ) && isObjectBindingPattern ( original . parent ) ) {
204
+ const symbol = checker . getSymbolAtLocation ( original . name ) ;
205
+ const renameInfo = symbol && identsToRenameMap . get ( String ( getSymbolId ( symbol ) ) ) ;
206
+ if ( renameInfo && renameInfo . text !== ( original . name || original . propertyName ) . getText ( ) ) {
207
+ return factory . createBindingElement (
208
+ original . dotDotDotToken ,
209
+ original . propertyName || original . name ,
210
+ renameInfo ,
211
+ original . initializer ) ;
212
+ }
213
+ }
214
+ else if ( isIdentifier ( original ) ) {
215
+ const symbol = checker . getSymbolAtLocation ( original ) ;
216
+ const renameInfo = symbol && identsToRenameMap . get ( String ( getSymbolId ( symbol ) ) ) ;
217
+ if ( renameInfo ) {
218
+ return factory . createIdentifier ( renameInfo . text ) ;
219
+ }
220
+ }
221
+ } ) ;
203
222
}
204
223
205
224
function getNewNameIfConflict ( name : Identifier , originalNames : ReadonlyESMap < string , Symbol [ ] > ) : SynthIdentifier {
@@ -289,7 +308,7 @@ namespace ts.codefix {
289
308
290
309
const tryStatement = factory . createTryStatement ( tryBlock , catchClause , /*finallyBlock*/ undefined ) ;
291
310
const destructuredResult = prevArgName && varDeclIdentifier && isSynthBindingPattern ( prevArgName )
292
- && factory . createVariableStatement ( /*modifiers*/ undefined , factory . createVariableDeclarationList ( [ factory . createVariableDeclaration ( getSynthesizedDeepCloneWithRenames ( prevArgName . bindingPattern ) , /*exclamationToken*/ undefined , /*type*/ undefined , varDeclIdentifier ) ] , NodeFlags . Const ) ) ;
311
+ && factory . createVariableStatement ( /*modifiers*/ undefined , factory . createVariableDeclarationList ( [ factory . createVariableDeclaration ( getSynthesizedDeepClone ( prevArgName . bindingPattern ) , /*exclamationToken*/ undefined , /*type*/ undefined , varDeclIdentifier ) ] , NodeFlags . Const ) ) ;
293
312
return compact ( [ varDeclList , tryStatement , destructuredResult ] ) ;
294
313
}
295
314
0 commit comments