@@ -320,10 +320,14 @@ namespace ts.textChanges {
320
320
return this . replaceRangeWithNodes ( sourceFile , getAdjustedRange ( sourceFile , startNode , endNode , options ) , newNodes , options ) ;
321
321
}
322
322
323
+ private nextCommaToken ( sourceFile : SourceFile , node : Node ) : Node | undefined {
324
+ const next = findNextToken ( node , node . parent , sourceFile ) ;
325
+ return next && next . kind === SyntaxKind . CommaToken ? next : undefined ;
326
+ }
327
+
323
328
public replacePropertyAssignment ( sourceFile : SourceFile , oldNode : PropertyAssignment , newNode : PropertyAssignment ) {
324
- return this . replaceNode ( sourceFile , oldNode , newNode , {
325
- suffix : "," + this . newLineCharacter
326
- } ) ;
329
+ const suffix = this . nextCommaToken ( sourceFile , oldNode ) ? "" : ( "," + this . newLineCharacter ) ;
330
+ return this . replaceNode ( sourceFile , oldNode , newNode , { suffix } ) ;
327
331
}
328
332
329
333
private insertNodeAt ( sourceFile : SourceFile , pos : number , newNode : Node , options : InsertNodeOptions = { } ) {
@@ -465,6 +469,11 @@ namespace ts.textChanges {
465
469
}
466
470
}
467
471
472
+ public insertNodeAfterComma ( sourceFile : SourceFile , after : Node , newNode : Node ) : void {
473
+ const endPosition = this . insertNodeAfterWorker ( sourceFile , this . nextCommaToken ( sourceFile , after ) || after , newNode ) ;
474
+ this . insertNodeAt ( sourceFile , endPosition , newNode , this . getInsertNodeAfterOptions ( sourceFile , after ) ) ;
475
+ }
476
+
468
477
public insertNodeAfter ( sourceFile : SourceFile , after : Node , newNode : Node ) : void {
469
478
const endPosition = this . insertNodeAfterWorker ( sourceFile , after , newNode ) ;
470
479
this . insertNodeAt ( sourceFile , endPosition , newNode , this . getInsertNodeAfterOptions ( sourceFile , after ) ) ;
0 commit comments