extract getEdits for template literal

This commit is contained in:
BigAru
2018-12-09 01:07:05 +01:00
parent 16109dfd00
commit 3ce216849a
@@ -41,11 +41,7 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
switch (actionName) {
case toTemplateLiteralActionName:
const maybeBinary = getParentBinaryExpression(node);
const arrayOfNodes = transformTreeToArray(maybeBinary);
const templateLiteral = nodesToTemplate(arrayOfNodes);
const edits = textChanges.ChangeTracker.with(context, t => t.replaceNode(file, maybeBinary, templateLiteral));
return { edits };
return { edits: getEditsForToTemplateLiteral(context, node) };
case toStringConcatenationActionName:
return { edits: getEditsForToStringConcatenation(context, node) };
@@ -55,6 +51,13 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
}
}
function getEditsForToTemplateLiteral(context: RefactorContext, node: Node) {
const maybeBinary = getParentBinaryExpression(node);
const arrayOfNodes = transformTreeToArray(maybeBinary);
const templateLiteral = nodesToTemplate(arrayOfNodes);
return textChanges.ChangeTracker.with(context, t => t.replaceNode(context.file, maybeBinary, templateLiteral));
}
function getEditsForToStringConcatenation(context: RefactorContext, node: Node) {
const templateLiteral = findAncestor(node, n => isTemplateLiteral(n))! as TemplateLiteral;