From 91f60b82ebe93f953e2f9d7db6da7e2b12cd7e20 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 1 Oct 2018 17:50:47 -0700 Subject: [PATCH] textChanges: Reuse some methods --- src/services/textChanges.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index 3b6da401db080..abd153f0bacd7 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -295,7 +295,7 @@ namespace ts.textChanges { } private insertNodesAt(sourceFile: SourceFile, pos: number, newNodes: ReadonlyArray, options: ReplaceWithMultipleNodesOptions = {}): void { - this.changes.push({ kind: ChangeKind.ReplaceWithMultipleNodes, sourceFile, options, nodes: newNodes, range: { pos, end: pos } }); + this.replaceRangeWithNodes(sourceFile, createRange(pos), newNodes, options); } public insertNodeAtTopOfFile(sourceFile: SourceFile, newNode: Statement, blankLineBetween: boolean): void { @@ -312,7 +312,7 @@ namespace ts.textChanges { public insertModifierBefore(sourceFile: SourceFile, modifier: SyntaxKind, before: Node): void { const pos = before.getStart(sourceFile); - this.replaceRange(sourceFile, { pos, end: pos }, createToken(modifier), { suffix: " " }); + this.insertNodeAt(sourceFile, pos, createToken(modifier), { suffix: " " }); } public insertLastModifierBefore(sourceFile: SourceFile, modifier: SyntaxKind, before: Node): void { @@ -322,7 +322,7 @@ namespace ts.textChanges { } const pos = before.modifiers.end; - this.replaceRange(sourceFile, { pos, end: pos }, createToken(modifier), { prefix: " " }); + this.insertNodeAt(sourceFile, pos, createToken(modifier), { prefix: " " }); } public insertCommentBeforeLine(sourceFile: SourceFile, lineNumber: number, position: number, commentText: string): void { @@ -413,7 +413,7 @@ namespace ts.textChanges { public insertNodeAtEndOfScope(sourceFile: SourceFile, scope: Node, newNode: Node): void { const pos = getAdjustedStartPosition(sourceFile, scope.getLastToken()!, {}, Position.Start); - this.replaceRange(sourceFile, { pos, end: pos }, newNode, { + this.insertNodeAt(sourceFile, pos, newNode, { prefix: isLineBreak(sourceFile.text.charCodeAt(scope.getLastToken()!.pos)) ? this.newLineCharacter : this.newLineCharacter + this.newLineCharacter, suffix: this.newLineCharacter });