optimize and add more tests for parenthesized case
This commit is contained in:
parent
2a15acbbfd
commit
935cf04e40
|
@ -33,7 +33,16 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
|
|||
|
||||
function getNodeOrParentOfParentheses(file: SourceFile, startPosition: number) {
|
||||
const node = getTokenAtPosition(file, startPosition);
|
||||
if (isParenthesizedExpression(node.parent) && isBinaryExpression(node.parent.parent)) return node.parent.parent;
|
||||
const nestedBinary = getParentBinaryExpression(node);
|
||||
const isNonStringBinary = !isStringConcatenationValid(nestedBinary);
|
||||
|
||||
if (
|
||||
isNonStringBinary &&
|
||||
isParenthesizedExpression(nestedBinary.parent) &&
|
||||
isBinaryExpression(nestedBinary.parent.parent)
|
||||
) {
|
||||
return nestedBinary.parent.parent;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = "foobar is " + (/*x*/42/*y*/ + 6) + " years old"
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to template literal",
|
||||
actionDescription: "Convert to template literal",
|
||||
newContent:
|
||||
`const foo = \`foobar is \${42 + 6} years old\``,
|
||||
});
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// const foo = "foobar is " + (/*x*/42/*y*/ + 6 + "str") + " years old"
|
||||
|
||||
goTo.select("x", "y");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert string concatenation or template literal",
|
||||
actionName: "Convert to template literal",
|
||||
actionDescription: "Convert to template literal",
|
||||
newContent:
|
||||
`const foo = "foobar is " + (\`\${42 + 6}str\`) + " years old"`,
|
||||
});
|
||||
|
Loading…
Reference in a new issue