mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
extract getEdits for template literal
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user