Skip to content

Commit 3ce2168

Browse files
committed
extract getEdits for template literal
1 parent 16109df commit 3ce2168

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/services/refactors/convertStringOrTemplateLiteral.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
4141

4242
switch (actionName) {
4343
case toTemplateLiteralActionName:
44-
const maybeBinary = getParentBinaryExpression(node);
45-
const arrayOfNodes = transformTreeToArray(maybeBinary);
46-
const templateLiteral = nodesToTemplate(arrayOfNodes);
47-
const edits = textChanges.ChangeTracker.with(context, t => t.replaceNode(file, maybeBinary, templateLiteral));
48-
return { edits };
44+
return { edits: getEditsForToTemplateLiteral(context, node) };
4945

5046
case toStringConcatenationActionName:
5147
return { edits: getEditsForToStringConcatenation(context, node) };
@@ -55,6 +51,13 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
5551
}
5652
}
5753

54+
function getEditsForToTemplateLiteral(context: RefactorContext, node: Node) {
55+
const maybeBinary = getParentBinaryExpression(node);
56+
const arrayOfNodes = transformTreeToArray(maybeBinary);
57+
const templateLiteral = nodesToTemplate(arrayOfNodes);
58+
return textChanges.ChangeTracker.with(context, t => t.replaceNode(context.file, maybeBinary, templateLiteral));
59+
}
60+
5861
function getEditsForToStringConcatenation(context: RefactorContext, node: Node) {
5962
const templateLiteral = findAncestor(node, n => isTemplateLiteral(n))! as TemplateLiteral;
6063

0 commit comments

Comments
 (0)