@@ -288,26 +288,15 @@ namespace ts.textChanges {
288
288
}
289
289
290
290
public replaceNode ( sourceFile : SourceFile , oldNode : Node , newNode : Node , options : ChangeNodeOptions = { } ) {
291
- const startPosition = getAdjustedStartPosition ( sourceFile , oldNode , options , Position . Start ) ;
292
- const endPosition = getAdjustedEndPosition ( sourceFile , oldNode , options ) ;
293
- return this . replaceWithSingle ( sourceFile , startPosition , endPosition , newNode , options ) ;
291
+ const pos = getAdjustedStartPosition ( sourceFile , oldNode , options , Position . Start ) ;
292
+ const end = getAdjustedEndPosition ( sourceFile , oldNode , options ) ;
293
+ return this . replaceRange ( sourceFile , { pos , end } , newNode , options ) ;
294
294
}
295
295
296
296
public replaceNodeRange ( sourceFile : SourceFile , startNode : Node , endNode : Node , newNode : Node , options : ChangeNodeOptions = { } ) {
297
- const startPosition = getAdjustedStartPosition ( sourceFile , startNode , options , Position . Start ) ;
298
- const endPosition = getAdjustedEndPosition ( sourceFile , endNode , options ) ;
299
- return this . replaceWithSingle ( sourceFile , startPosition , endPosition , newNode , options ) ;
300
- }
301
-
302
- private replaceWithSingle ( sourceFile : SourceFile , startPosition : number , endPosition : number , newNode : Node , options : ChangeNodeOptions ) : this {
303
- this . changes . push ( {
304
- kind : ChangeKind . ReplaceWithSingleNode ,
305
- sourceFile,
306
- options,
307
- node : newNode ,
308
- range : { pos : startPosition , end : endPosition }
309
- } ) ;
310
- return this ;
297
+ const pos = getAdjustedStartPosition ( sourceFile , startNode , options , Position . Start ) ;
298
+ const end = getAdjustedEndPosition ( sourceFile , endNode , options ) ;
299
+ return this . replaceRange ( sourceFile , { pos, end } , newNode , options ) ;
311
300
}
312
301
313
302
private replaceWithMultiple ( sourceFile : SourceFile , startPosition : number , endPosition : number , newNodes : ReadonlyArray < Node > , options : ChangeMultipleNodesOptions ) : this {
@@ -343,18 +332,18 @@ namespace ts.textChanges {
343
332
}
344
333
345
334
public insertNodeBefore ( sourceFile : SourceFile , before : Node , newNode : Node , blankLineBetween = false ) {
346
- const startPosition = getAdjustedStartPosition ( sourceFile , before , { } , Position . Start ) ;
347
- return this . replaceWithSingle ( sourceFile , startPosition , startPosition , newNode , this . getOptionsForInsertNodeBefore ( before , blankLineBetween ) ) ;
335
+ const pos = getAdjustedStartPosition ( sourceFile , before , { } , Position . Start ) ;
336
+ return this . replaceRange ( sourceFile , { pos , end : pos } , newNode , this . getOptionsForInsertNodeBefore ( before , blankLineBetween ) ) ;
348
337
}
349
338
350
339
public insertModifierBefore ( sourceFile : SourceFile , modifier : SyntaxKind , before : Node ) : void {
351
340
const pos = before . getStart ( sourceFile ) ;
352
- this . replaceWithSingle ( sourceFile , pos , pos , createToken ( modifier ) , { suffix : " " } ) ;
341
+ this . replaceRange ( sourceFile , { pos, end : pos } , createToken ( modifier ) , { suffix : " " } ) ;
353
342
}
354
343
355
344
public changeIdentifierToPropertyAccess ( sourceFile : SourceFile , prefix : string , node : Identifier ) : void {
356
- const startPosition = getAdjustedStartPosition ( sourceFile , node , { } , Position . Start ) ;
357
- this . replaceWithSingle ( sourceFile , startPosition , startPosition , createPropertyAccess ( createIdentifier ( prefix ) , "" ) , { } ) ;
345
+ const pos = getAdjustedStartPosition ( sourceFile , node , { } , Position . Start ) ;
346
+ this . replaceRange ( sourceFile , { pos , end : pos } , createPropertyAccess ( createIdentifier ( prefix ) , "" ) , { } ) ;
358
347
}
359
348
360
349
private getOptionsForInsertNodeBefore ( before : Node , doubleNewlines : boolean ) : ChangeNodeOptions {
@@ -392,8 +381,8 @@ namespace ts.textChanges {
392
381
}
393
382
394
383
public insertNodeAtEndOfScope ( sourceFile : SourceFile , scope : Node , newNode : Node ) : void {
395
- const startPosition = getAdjustedStartPosition ( sourceFile , scope . getLastToken ( ) , { } , Position . Start ) ;
396
- this . replaceWithSingle ( sourceFile , startPosition , startPosition , newNode , {
384
+ const pos = getAdjustedStartPosition ( sourceFile , scope . getLastToken ( ) , { } , Position . Start ) ;
385
+ this . replaceRange ( sourceFile , { pos , end : pos } , newNode , {
397
386
prefix : isLineBreak ( sourceFile . text . charCodeAt ( scope . getLastToken ( ) . pos ) ) ? this . newLineCharacter : this . newLineCharacter + this . newLineCharacter ,
398
387
suffix : this . newLineCharacter
399
388
} ) ;
@@ -435,7 +424,7 @@ namespace ts.textChanges {
435
424
}
436
425
}
437
426
const endPosition = getAdjustedEndPosition ( sourceFile , after , { } ) ;
438
- return this . replaceWithSingle ( sourceFile , endPosition , endPosition , newNode , this . getInsertNodeAfterOptions ( after ) ) ;
427
+ return this . replaceRange ( sourceFile , { pos : endPosition , end : endPosition } , newNode , this . getInsertNodeAfterOptions ( after ) ) ;
439
428
}
440
429
441
430
private getInsertNodeAfterOptions ( node : Node ) : InsertNodeOptions {
0 commit comments