@@ -993,6 +993,27 @@ namespace ts.textChanges {
993
993
return skipTrivia ( sourceFile . text , getAdjustedStartPosition ( sourceFile , node , { leadingTriviaOption : LeadingTriviaOption . IncludeAll } ) , /*stopAfterLineBreak*/ false , /*stopAtComments*/ true ) ;
994
994
}
995
995
996
+ function endPositionToDeleteNodeInList ( sourceFile : SourceFile , node : Node , prevNode : Node | undefined , nextNode : Node ) : number {
997
+ const end = startPositionToDeleteNodeInList ( sourceFile , nextNode ) ;
998
+ if ( prevNode === undefined || positionsAreOnSameLine ( getAdjustedEndPosition ( sourceFile , node , { } ) , end , sourceFile ) ) {
999
+ return end ;
1000
+ }
1001
+ const token = findPrecedingToken ( nextNode . getStart ( sourceFile ) , sourceFile ) ;
1002
+ if ( isSeparator ( node , token ) ) {
1003
+ const prevToken = findPrecedingToken ( node . getStart ( sourceFile ) , sourceFile ) ;
1004
+ if ( isSeparator ( prevNode , prevToken ) ) {
1005
+ const pos = skipTrivia ( sourceFile . text , token . getEnd ( ) , /*stopAfterLineBreak*/ true , /*stopAtComments*/ true ) ;
1006
+ if ( positionsAreOnSameLine ( prevToken . getStart ( sourceFile ) , token . getStart ( sourceFile ) , sourceFile ) ) {
1007
+ return isLineBreak ( sourceFile . text . charCodeAt ( pos - 1 ) ) ? pos - 1 : pos ;
1008
+ }
1009
+ if ( isLineBreak ( sourceFile . text . charCodeAt ( pos ) ) ) {
1010
+ return pos ;
1011
+ }
1012
+ }
1013
+ }
1014
+ return end ;
1015
+ }
1016
+
996
1017
function getClassOrObjectBraceEnds ( cls : ClassLikeDeclaration | InterfaceDeclaration | ObjectLiteralExpression , sourceFile : SourceFile ) : [ number | undefined , number | undefined ] {
997
1018
const open = findChildOfKind ( cls , SyntaxKind . OpenBraceToken , sourceFile ) ;
998
1019
const close = findChildOfKind ( cls , SyntaxKind . CloseBraceToken , sourceFile ) ;
@@ -1589,9 +1610,10 @@ namespace ts.textChanges {
1589
1610
// That's handled in the end by `finishTrailingCommaAfterDeletingNodesInList`.
1590
1611
Debug . assert ( ! deletedNodesInLists . has ( node ) , "Deleting a node twice" ) ;
1591
1612
deletedNodesInLists . add ( node ) ;
1613
+
1592
1614
changes . deleteRange ( sourceFile , {
1593
1615
pos : startPositionToDeleteNodeInList ( sourceFile , node ) ,
1594
- end : index === containingList . length - 1 ? getAdjustedEndPosition ( sourceFile , node , { } ) : startPositionToDeleteNodeInList ( sourceFile , containingList [ index + 1 ] ) ,
1616
+ end : index === containingList . length - 1 ? getAdjustedEndPosition ( sourceFile , node , { } ) : endPositionToDeleteNodeInList ( sourceFile , node , containingList [ index - 1 ] , containingList [ index + 1 ] ) ,
1595
1617
} ) ;
1596
1618
}
1597
1619
}
0 commit comments