@@ -282,7 +282,7 @@ namespace ts.textChanges {
282
282
return this ;
283
283
}
284
284
285
- public replaceRange ( sourceFile : SourceFile , range : TextRange , newNode : Node , options : InsertNodeOptions = { } ) {
285
+ public replaceRange ( sourceFile : SourceFile , range : TextRange , newNode : Node , options : ChangeNodeOptions = { } ) {
286
286
this . changes . push ( { kind : ChangeKind . ReplaceWithSingleNode , sourceFile, range, options, node : newNode } ) ;
287
287
return this ;
288
288
}
@@ -299,23 +299,29 @@ namespace ts.textChanges {
299
299
return this . replaceRange ( sourceFile , { pos, end } , newNode , options ) ;
300
300
}
301
301
302
- private replaceWithMultiple ( sourceFile : SourceFile , startPosition : number , endPosition : number , newNodes : ReadonlyArray < Node > , options : ChangeMultipleNodesOptions ) : this {
303
- this . changes . push ( {
304
- kind : ChangeKind . ReplaceWithMultipleNodes ,
305
- sourceFile,
306
- options,
307
- nodes : newNodes ,
308
- range : { pos : startPosition , end : endPosition }
309
- } ) ;
302
+ private getDefaultChangeMultipleNodesOptions ( ) : ChangeMultipleNodesOptions {
303
+ return {
304
+ nodeSeparator : this . newLineCharacter ,
305
+ useNonAdjustedStartPosition : true ,
306
+ useNonAdjustedEndPosition : true ,
307
+ } ;
308
+ }
309
+
310
+ public replaceRangeWithNodes ( sourceFile : SourceFile , range : TextRange , newNodes : ReadonlyArray < Node > , options : ChangeMultipleNodesOptions = this . getDefaultChangeMultipleNodesOptions ( ) ) {
311
+ this . changes . push ( { kind : ChangeKind . ReplaceWithMultipleNodes , sourceFile, range, options, nodes : newNodes } ) ;
310
312
return this ;
311
313
}
312
314
313
- public replaceNodeWithNodes ( sourceFile : SourceFile , oldNode : Node , newNodes : ReadonlyArray < Node > ) : void {
314
- this . replaceWithMultiple ( sourceFile , oldNode . getStart ( sourceFile ) , oldNode . getEnd ( ) , newNodes , { nodeSeparator : this . newLineCharacter } ) ;
315
+ public replaceNodeWithNodes ( sourceFile : SourceFile , oldNode : Node , newNodes : ReadonlyArray < Node > , options : ChangeMultipleNodesOptions = this . getDefaultChangeMultipleNodesOptions ( ) ) {
316
+ const pos = getAdjustedStartPosition ( sourceFile , oldNode , options , Position . Start ) ;
317
+ const end = getAdjustedEndPosition ( sourceFile , oldNode , options ) ;
318
+ return this . replaceRangeWithNodes ( sourceFile , { pos, end } , newNodes , options ) ;
315
319
}
316
320
317
- public replaceNodesWithNodes ( sourceFile : SourceFile , oldNodes : ReadonlyArray < Node > , newNodes : ReadonlyArray < Node > ) : void {
318
- this . replaceWithMultiple ( sourceFile , first ( oldNodes ) . getStart ( sourceFile ) , last ( oldNodes ) . getEnd ( ) , newNodes , { nodeSeparator : this . newLineCharacter } ) ;
321
+ public replaceNodeRangeWithNodes ( sourceFile : SourceFile , startNode : Node , endNode : Node , newNodes : ReadonlyArray < Node > , options : ChangeMultipleNodesOptions = this . getDefaultChangeMultipleNodesOptions ( ) ) {
322
+ const pos = getAdjustedStartPosition ( sourceFile , startNode , options , Position . Start ) ;
323
+ const end = getAdjustedEndPosition ( sourceFile , endNode , options ) ;
324
+ return this . replaceRangeWithNodes ( sourceFile , { pos, end } , newNodes , options ) ;
319
325
}
320
326
321
327
private insertNodeAt ( sourceFile : SourceFile , pos : number , newNode : Node , options : InsertNodeOptions = { } ) {
0 commit comments