Skip to content

Commit 16766b1

Browse files
author
Andy
authored
textChanges: Reuse some methods (microsoft#27492)
1 parent 5f96fb1 commit 16766b1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/services/textChanges.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ namespace ts.textChanges {
295295
}
296296

297297
private insertNodesAt(sourceFile: SourceFile, pos: number, newNodes: ReadonlyArray<Node>, options: ReplaceWithMultipleNodesOptions = {}): void {
298-
this.changes.push({ kind: ChangeKind.ReplaceWithMultipleNodes, sourceFile, options, nodes: newNodes, range: { pos, end: pos } });
298+
this.replaceRangeWithNodes(sourceFile, createRange(pos), newNodes, options);
299299
}
300300

301301
public insertNodeAtTopOfFile(sourceFile: SourceFile, newNode: Statement, blankLineBetween: boolean): void {
@@ -312,7 +312,7 @@ namespace ts.textChanges {
312312

313313
public insertModifierBefore(sourceFile: SourceFile, modifier: SyntaxKind, before: Node): void {
314314
const pos = before.getStart(sourceFile);
315-
this.replaceRange(sourceFile, { pos, end: pos }, createToken(modifier), { suffix: " " });
315+
this.insertNodeAt(sourceFile, pos, createToken(modifier), { suffix: " " });
316316
}
317317

318318
public insertLastModifierBefore(sourceFile: SourceFile, modifier: SyntaxKind, before: Node): void {
@@ -322,7 +322,7 @@ namespace ts.textChanges {
322322
}
323323

324324
const pos = before.modifiers.end;
325-
this.replaceRange(sourceFile, { pos, end: pos }, createToken(modifier), { prefix: " " });
325+
this.insertNodeAt(sourceFile, pos, createToken(modifier), { prefix: " " });
326326
}
327327

328328
public insertCommentBeforeLine(sourceFile: SourceFile, lineNumber: number, position: number, commentText: string): void {
@@ -413,7 +413,7 @@ namespace ts.textChanges {
413413

414414
public insertNodeAtEndOfScope(sourceFile: SourceFile, scope: Node, newNode: Node): void {
415415
const pos = getAdjustedStartPosition(sourceFile, scope.getLastToken()!, {}, Position.Start);
416-
this.replaceRange(sourceFile, { pos, end: pos }, newNode, {
416+
this.insertNodeAt(sourceFile, pos, newNode, {
417417
prefix: isLineBreak(sourceFile.text.charCodeAt(scope.getLastToken()!.pos)) ? this.newLineCharacter : this.newLineCharacter + this.newLineCharacter,
418418
suffix: this.newLineCharacter
419419
});

0 commit comments

Comments
 (0)