Skip to content

Commit ab5596e

Browse files
committed
Call replaceNode rather than replaceRange
...where convenient. Same for deleteNode/Range.
1 parent ad68fa8 commit ab5596e

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

src/services/codefixes/fixExtendsInterfaceBecomesImplements.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace ts.codefix {
2727
}
2828

2929
function doChanges(changes: textChanges.ChangeTracker, sourceFile: SourceFile, extendsToken: Node, heritageClauses: ReadonlyArray<HeritageClause>): void {
30-
changes.replaceRange(sourceFile, { pos: extendsToken.getStart(), end: extendsToken.end }, createToken(SyntaxKind.ImplementsKeyword));
30+
changes.replaceNode(sourceFile, extendsToken, createToken(SyntaxKind.ImplementsKeyword), textChanges.useNonAdjustedPositions);
3131

3232
// If there is already an implements clause, replace the implements keyword with a comma.
3333
if (heritageClauses.length === 2 &&

src/services/codefixes/fixForgottenThisPropertyAccess.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ namespace ts.codefix {
2323
function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, token: Identifier): void {
2424
// TODO (https://github.com/Microsoft/TypeScript/issues/21246): use shared helper
2525
suppressLeadingAndTrailingTrivia(token);
26-
changes.replaceRange(sourceFile, { pos: token.getStart(), end: token.end }, createPropertyAccess(createThis(), token));
26+
changes.replaceNode(sourceFile, token, createPropertyAccess(createThis(), token), textChanges.useNonAdjustedPositions);
2727
}
2828
}

src/services/codefixes/fixUnusedIdentifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ namespace ts.codefix {
140140
// and trailing trivia will remain.
141141
suppressLeadingAndTrailingTrivia(newFunction);
142142

143-
changes.replaceRange(sourceFile, { pos: oldFunction.getStart(), end: oldFunction.end }, newFunction);
143+
changes.replaceNode(sourceFile, oldFunction, newFunction, textChanges.useNonAdjustedPositions);
144144
}
145145
else {
146146
changes.deleteNodeInList(sourceFile, parent);

src/services/refactors/annotateWithTypeFromJSDoc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace ts.refactor.annotateWithTypeFromJSDoc {
7676
const changeTracker = textChanges.ChangeTracker.fromContext(context);
7777
const declarationWithType = addType(decl, transformJSDocType(jsdocType) as TypeNode);
7878
suppressLeadingAndTrailingTrivia(declarationWithType);
79-
changeTracker.replaceRange(sourceFile, { pos: decl.getStart(), end: decl.end }, declarationWithType);
79+
changeTracker.replaceNode(sourceFile, decl, declarationWithType, textChanges.useNonAdjustedPositions);
8080
return {
8181
edits: changeTracker.getChanges(),
8282
renameFilename: undefined,
@@ -91,7 +91,7 @@ namespace ts.refactor.annotateWithTypeFromJSDoc {
9191
const changeTracker = textChanges.ChangeTracker.fromContext(context);
9292
const functionWithType = addTypesToFunctionLike(decl);
9393
suppressLeadingAndTrailingTrivia(functionWithType);
94-
changeTracker.replaceRange(sourceFile, { pos: decl.getStart(), end: decl.end }, functionWithType);
94+
changeTracker.replaceNode(sourceFile, decl, functionWithType, textChanges.useNonAdjustedPositions);
9595
return {
9696
edits: changeTracker.getChanges(),
9797
renameFilename: undefined,

src/services/refactors/extractSymbol.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ namespace ts.refactor.extractSymbol {
10531053
changeTracker.insertNodeBefore(context.file, nodeToInsertBefore, newVariable, /*blankLineBetween*/ true);
10541054

10551055
// Consume
1056-
changeTracker.replaceRange(context.file, { pos: node.getStart(), end: node.end }, localReference);
1056+
changeTracker.replaceNode(context.file, node, localReference, textChanges.useNonAdjustedPositions);
10571057
}
10581058
else {
10591059
const newVariableDeclaration = createVariableDeclaration(localNameText, variableType, initializer);
@@ -1070,15 +1070,15 @@ namespace ts.refactor.extractSymbol {
10701070

10711071
// Consume
10721072
const localReference = createIdentifier(localNameText);
1073-
changeTracker.replaceRange(context.file, { pos: node.getStart(), end: node.end }, localReference);
1073+
changeTracker.replaceNode(context.file, node, localReference, textChanges.useNonAdjustedPositions);
10741074
}
10751075
else if (node.parent.kind === SyntaxKind.ExpressionStatement && scope === findAncestor(node, isScope)) {
10761076
// If the parent is an expression statement and the target scope is the immediately enclosing one,
10771077
// replace the statement with the declaration.
10781078
const newVariableStatement = createVariableStatement(
10791079
/*modifiers*/ undefined,
10801080
createVariableDeclarationList([newVariableDeclaration], NodeFlags.Const));
1081-
changeTracker.replaceRange(context.file, { pos: node.parent.getStart(), end: node.parent.end }, newVariableStatement);
1081+
changeTracker.replaceNode(context.file, node.parent, newVariableStatement, textChanges.useNonAdjustedPositions);
10821082
}
10831083
else {
10841084
const newVariableStatement = createVariableStatement(
@@ -1097,11 +1097,11 @@ namespace ts.refactor.extractSymbol {
10971097
// Consume
10981098
if (node.parent.kind === SyntaxKind.ExpressionStatement) {
10991099
// If the parent is an expression statement, delete it.
1100-
changeTracker.deleteRange(context.file, { pos: node.parent.getStart(), end: node.parent.end });
1100+
changeTracker.deleteNode(context.file, node.parent, textChanges.useNonAdjustedPositions);
11011101
}
11021102
else {
11031103
const localReference = createIdentifier(localNameText);
1104-
changeTracker.replaceRange(context.file, { pos: node.getStart(), end: node.end }, localReference);
1104+
changeTracker.replaceNode(context.file, node, localReference, textChanges.useNonAdjustedPositions);
11051105
}
11061106
}
11071107
}

0 commit comments

Comments
 (0)