@@ -276,11 +276,15 @@ namespace ts.textChanges {
276
276
return this . replaceRangeWithNodes ( sourceFile , getAdjustedRange ( sourceFile , oldNode , oldNode , options ) , newNodes , options ) ;
277
277
}
278
278
279
+ public replaceNodeWithText ( sourceFile : SourceFile , oldNode : Node , text : string ) : void {
280
+ this . replaceRangeWithText ( sourceFile , getAdjustedRange ( sourceFile , oldNode , oldNode , useNonAdjustedPositions ) , text ) ;
281
+ }
282
+
279
283
public replaceNodeRangeWithNodes ( sourceFile : SourceFile , startNode : Node , endNode : Node , newNodes : ReadonlyArray < Node > , options : ReplaceWithMultipleNodesOptions & ConfigurableStartEnd = useNonAdjustedPositions ) {
280
284
return this . replaceRangeWithNodes ( sourceFile , getAdjustedRange ( sourceFile , startNode , endNode , options ) , newNodes , options ) ;
281
285
}
282
286
283
- private nextCommaToken ( sourceFile : SourceFile , node : Node ) : Node | undefined {
287
+ private nextCommaToken ( sourceFile : SourceFile , node : Node ) : Node | undefined {
284
288
const next = findNextToken ( node , node . parent , sourceFile ) ;
285
289
return next && next . kind === SyntaxKind . CommaToken ? next : undefined ;
286
290
}
@@ -690,7 +694,7 @@ namespace ts.textChanges {
690
694
}
691
695
692
696
private finishDeleteDeclarations ( ) : void {
693
- const deletedNodesInLists = new NodeSet ( ) ; // Stores ids of nodes in lists that we already deleted. Used to avoid deleting `, ` twice in `a, b`.
697
+ const deletedNodesInLists = new NodeSet ( ) ; // Stores nodes in lists that we already deleted. Used to avoid deleting `, ` twice in `a, b`.
694
698
for ( const { sourceFile, node } of this . deletedNodes ) {
695
699
if ( ! this . deletedNodes . some ( d => d . sourceFile === sourceFile && rangeContainsRangeExclusive ( d . node , node ) ) ) {
696
700
if ( isArray ( node ) ) {
@@ -1053,25 +1057,13 @@ namespace ts.textChanges {
1053
1057
switch ( node . kind ) {
1054
1058
case SyntaxKind . Parameter : {
1055
1059
const oldFunction = node . parent ;
1056
- if ( isArrowFunction ( oldFunction ) && oldFunction . parameters . length === 1 ) {
1060
+ if ( isArrowFunction ( oldFunction ) &&
1061
+ oldFunction . parameters . length === 1 &&
1062
+ ! findChildOfKind ( oldFunction , SyntaxKind . OpenParenToken , sourceFile ) ) {
1057
1063
// Lambdas with exactly one parameter are special because, after removal, there
1058
1064
// must be an empty parameter list (i.e. `()`) and this won't necessarily be the
1059
1065
// case if the parameter is simply removed (e.g. in `x => 1`).
1060
- const newFunction = updateArrowFunction (
1061
- oldFunction ,
1062
- oldFunction . modifiers ,
1063
- oldFunction . typeParameters ,
1064
- /*parameters*/ undefined ! , // TODO: GH#18217
1065
- oldFunction . type ,
1066
- oldFunction . equalsGreaterThanToken ,
1067
- oldFunction . body ) ;
1068
-
1069
- // Drop leading and trailing trivia of the new function because we're only going
1070
- // to replace the span (vs the full span) of the old function - the old leading
1071
- // and trailing trivia will remain.
1072
- suppressLeadingAndTrailingTrivia ( newFunction ) ;
1073
-
1074
- changes . replaceNode ( sourceFile , oldFunction , newFunction ) ;
1066
+ changes . replaceNodeWithText ( sourceFile , node , "()" ) ;
1075
1067
}
1076
1068
else {
1077
1069
deleteNodeInList ( changes , deletedNodesInLists , sourceFile , node ) ;
0 commit comments