@@ -329,6 +329,10 @@ namespace ts.textChanges {
329329 this . insertText ( sourceFile , token . getStart ( sourceFile ) , text ) ;
330330 }
331331
332+ public replaceNodeWithText ( sourceFile : SourceFile , oldNode : Node , text : string , options : ChangeNodeOptions = useNonAdjustedPositions ) : void {
333+ return this . replaceRangeWithText ( sourceFile , getAdjustedRange ( sourceFile , oldNode , oldNode , options ) , text ) ;
334+ }
335+
332336 public replaceRangeWithText ( sourceFile : SourceFile , range : TextRange , text : string ) {
333337 this . changes . push ( { kind : ChangeKind . Text , sourceFile, range, text } ) ;
334338 }
@@ -1010,25 +1014,9 @@ namespace ts.textChanges {
10101014 switch ( node . kind ) {
10111015 case SyntaxKind . Parameter : {
10121016 const oldFunction = node . parent ;
1013- if ( isArrowFunction ( oldFunction ) && oldFunction . parameters . length === 1 ) {
1014- // Lambdas with exactly one parameter are special because, after removal, there
1015- // must be an empty parameter list (i.e. `()`) and this won't necessarily be the
1016- // case if the parameter is simply removed (e.g. in `x => 1`).
1017- const newFunction = updateArrowFunction (
1018- oldFunction ,
1019- oldFunction . modifiers ,
1020- oldFunction . typeParameters ,
1021- /*parameters*/ undefined ! , // TODO: GH#18217
1022- oldFunction . type ,
1023- oldFunction . equalsGreaterThanToken ,
1024- oldFunction . body ) ;
1025-
1026- // Drop leading and trailing trivia of the new function because we're only going
1027- // to replace the span (vs the full span) of the old function - the old leading
1028- // and trailing trivia will remain.
1029- suppressLeadingAndTrailingTrivia ( newFunction ) ;
1030-
1031- changes . replaceNode ( sourceFile , oldFunction , newFunction ) ;
1017+ if ( isArrowFunction ( oldFunction ) && oldFunction . parameters . length === 1 && ! findChildOfKind ( oldFunction , SyntaxKind . OpenParenToken , sourceFile ) ) {
1018+ // `x => {}` becomes `() => {}`
1019+ changes . replaceNodeWithText ( sourceFile , oldFunction . parameters [ 0 ] , "()" ) ;
10321020 }
10331021 else {
10341022 deleteNodeInList ( changes , deletedNodesInLists , sourceFile , node ) ;
0 commit comments