diff --git a/src/services/codefixes/fixExtendsInterfaceBecomesImplements.ts b/src/services/codefixes/fixExtendsInterfaceBecomesImplements.ts index d98ca556f47..551662210c1 100644 --- a/src/services/codefixes/fixExtendsInterfaceBecomesImplements.ts +++ b/src/services/codefixes/fixExtendsInterfaceBecomesImplements.ts @@ -27,7 +27,7 @@ namespace ts.codefix { } function doChanges(changes: textChanges.ChangeTracker, sourceFile: SourceFile, extendsToken: Node, heritageClauses: ReadonlyArray): void { - changes.replaceRange(sourceFile, { pos: extendsToken.getStart(), end: extendsToken.end }, createToken(SyntaxKind.ImplementsKeyword)); + changes.replaceNode(sourceFile, extendsToken, createToken(SyntaxKind.ImplementsKeyword), textChanges.useNonAdjustedPositions); // If there is already an implements clause, replace the implements keyword with a comma. if (heritageClauses.length === 2 && diff --git a/src/services/codefixes/fixForgottenThisPropertyAccess.ts b/src/services/codefixes/fixForgottenThisPropertyAccess.ts index 837487f1b8c..a3eb30159f5 100644 --- a/src/services/codefixes/fixForgottenThisPropertyAccess.ts +++ b/src/services/codefixes/fixForgottenThisPropertyAccess.ts @@ -23,6 +23,6 @@ namespace ts.codefix { function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, token: Identifier): void { // TODO (https://github.com/Microsoft/TypeScript/issues/21246): use shared helper suppressLeadingAndTrailingTrivia(token); - changes.replaceRange(sourceFile, { pos: token.getStart(), end: token.end }, createPropertyAccess(createThis(), token)); + changes.replaceNode(sourceFile, token, createPropertyAccess(createThis(), token), textChanges.useNonAdjustedPositions); } } \ No newline at end of file diff --git a/src/services/codefixes/fixUnusedIdentifier.ts b/src/services/codefixes/fixUnusedIdentifier.ts index 59d19a1bd9b..cb94c2112af 100644 --- a/src/services/codefixes/fixUnusedIdentifier.ts +++ b/src/services/codefixes/fixUnusedIdentifier.ts @@ -140,7 +140,7 @@ namespace ts.codefix { // and trailing trivia will remain. suppressLeadingAndTrailingTrivia(newFunction); - changes.replaceRange(sourceFile, { pos: oldFunction.getStart(), end: oldFunction.end }, newFunction); + changes.replaceNode(sourceFile, oldFunction, newFunction, textChanges.useNonAdjustedPositions); } else { changes.deleteNodeInList(sourceFile, parent); diff --git a/src/services/refactors/annotateWithTypeFromJSDoc.ts b/src/services/refactors/annotateWithTypeFromJSDoc.ts index 3116634cb52..6f87332aa96 100644 --- a/src/services/refactors/annotateWithTypeFromJSDoc.ts +++ b/src/services/refactors/annotateWithTypeFromJSDoc.ts @@ -76,7 +76,7 @@ namespace ts.refactor.annotateWithTypeFromJSDoc { const changeTracker = textChanges.ChangeTracker.fromContext(context); const declarationWithType = addType(decl, transformJSDocType(jsdocType) as TypeNode); suppressLeadingAndTrailingTrivia(declarationWithType); - changeTracker.replaceRange(sourceFile, { pos: decl.getStart(), end: decl.end }, declarationWithType); + changeTracker.replaceNode(sourceFile, decl, declarationWithType, textChanges.useNonAdjustedPositions); return { edits: changeTracker.getChanges(), renameFilename: undefined, @@ -91,7 +91,7 @@ namespace ts.refactor.annotateWithTypeFromJSDoc { const changeTracker = textChanges.ChangeTracker.fromContext(context); const functionWithType = addTypesToFunctionLike(decl); suppressLeadingAndTrailingTrivia(functionWithType); - changeTracker.replaceRange(sourceFile, { pos: decl.getStart(), end: decl.end }, functionWithType); + changeTracker.replaceNode(sourceFile, decl, functionWithType, textChanges.useNonAdjustedPositions); return { edits: changeTracker.getChanges(), renameFilename: undefined, diff --git a/src/services/refactors/extractSymbol.ts b/src/services/refactors/extractSymbol.ts index 20895d7992a..245f6d5859c 100644 --- a/src/services/refactors/extractSymbol.ts +++ b/src/services/refactors/extractSymbol.ts @@ -1053,7 +1053,7 @@ namespace ts.refactor.extractSymbol { changeTracker.insertNodeBefore(context.file, nodeToInsertBefore, newVariable, /*blankLineBetween*/ true); // Consume - changeTracker.replaceRange(context.file, { pos: node.getStart(), end: node.end }, localReference); + changeTracker.replaceNode(context.file, node, localReference, textChanges.useNonAdjustedPositions); } else { const newVariableDeclaration = createVariableDeclaration(localNameText, variableType, initializer); @@ -1070,7 +1070,7 @@ namespace ts.refactor.extractSymbol { // Consume const localReference = createIdentifier(localNameText); - changeTracker.replaceRange(context.file, { pos: node.getStart(), end: node.end }, localReference); + changeTracker.replaceNode(context.file, node, localReference, textChanges.useNonAdjustedPositions); } else if (node.parent.kind === SyntaxKind.ExpressionStatement && scope === findAncestor(node, isScope)) { // If the parent is an expression statement and the target scope is the immediately enclosing one, @@ -1078,7 +1078,7 @@ namespace ts.refactor.extractSymbol { const newVariableStatement = createVariableStatement( /*modifiers*/ undefined, createVariableDeclarationList([newVariableDeclaration], NodeFlags.Const)); - changeTracker.replaceRange(context.file, { pos: node.parent.getStart(), end: node.parent.end }, newVariableStatement); + changeTracker.replaceNode(context.file, node.parent, newVariableStatement, textChanges.useNonAdjustedPositions); } else { const newVariableStatement = createVariableStatement( @@ -1097,11 +1097,11 @@ namespace ts.refactor.extractSymbol { // Consume if (node.parent.kind === SyntaxKind.ExpressionStatement) { // If the parent is an expression statement, delete it. - changeTracker.deleteRange(context.file, { pos: node.parent.getStart(), end: node.parent.end }); + changeTracker.deleteNode(context.file, node.parent, textChanges.useNonAdjustedPositions); } else { const localReference = createIdentifier(localNameText); - changeTracker.replaceRange(context.file, { pos: node.getStart(), end: node.end }, localReference); + changeTracker.replaceNode(context.file, node, localReference, textChanges.useNonAdjustedPositions); } } }