mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
only show toString if expression is not binary
This commit is contained in:
@@ -15,20 +15,28 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
|
||||
let node = getTokenAtPosition(file, startPosition);
|
||||
if (isParenthesizedExpression(node.parent) && isBinaryExpression(node.parent.parent)) node = node.parent.parent;
|
||||
const maybeBinary = getParentBinaryExpression(node);
|
||||
const maybeTemplateExpression = findAncestor(node, n => isTemplateExpression(n));
|
||||
// const maybeTemplateExpression = findAncestor(node, n => isTemplateExpression(n));
|
||||
const actions: RefactorActionInfo[] = [];
|
||||
|
||||
if ((isBinaryExpression(maybeBinary) || isStringLiteral(maybeBinary)) && isStringConcatenationValid(maybeBinary)) {
|
||||
actions.push({ name: toTemplateLiteralActionName, description: toTemplateLiteralDescription });
|
||||
}
|
||||
|
||||
if ((isNoSubstitutionTemplateLiteral(node) && !isTaggedTemplateExpression(node.parent)) || (maybeTemplateExpression && !isTaggedTemplateExpression(maybeTemplateExpression.parent))) {
|
||||
// if ((isNoSubstitutionTemplateLiteral(node) && !isTaggedTemplateExpression(node.parent)) || (maybeTemplateExpression && !isTaggedTemplateExpression(maybeTemplateExpression.parent))) {
|
||||
if (isTemplateLike(node)) {
|
||||
actions.push({ name: toStringConcatenationActionName, description: toStringConcatenationDescription });
|
||||
}
|
||||
|
||||
return [{ name: refactorName, description: refactorDescription, actions }];
|
||||
}
|
||||
|
||||
function isTemplateLike(node: Node) {
|
||||
const isEmptyTL = isNoSubstitutionTemplateLiteral(node) && !isTaggedTemplateExpression(node.parent);
|
||||
const is = (isTemplateHead(node) || isTemplateMiddleOrTemplateTail(node)) && !isTaggedTemplateExpression(node.parent.parent);
|
||||
const ise = (isTemplateSpan(node.parent)) && !isTaggedTemplateExpression(node.parent.parent.parent);
|
||||
return isEmptyTL || is || ise;
|
||||
}
|
||||
|
||||
function getEditsForAction(context: RefactorContext, actionName: string): RefactorEditInfo | undefined {
|
||||
const { file, startPosition } = context;
|
||||
let node = getTokenAtPosition(file, startPosition);
|
||||
|
||||
Reference in New Issue
Block a user