@@ -12,8 +12,9 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
12
12
13
13
function getAvailableActions ( context : RefactorContext ) : ReadonlyArray < ApplicableRefactorInfo > {
14
14
const { file, startPosition } = context ;
15
- const node = getTokenAtPosition ( file , startPosition ) ;
16
- const maybeBinary = getParentBinaryExpression ( node ) ; containsString ( maybeBinary ) ;
15
+ let node = getTokenAtPosition ( file , startPosition ) ;
16
+ if ( isParenthesizedExpression ( node . parent ) && isBinaryExpression ( node . parent . parent ) ) node = node . parent . parent ;
17
+ const maybeBinary = getParentBinaryExpression ( node ) ;
17
18
const maybeTemplateExpression = findAncestor ( node , n => isTemplateExpression ( n ) ) ;
18
19
const actions : RefactorActionInfo [ ] = [ ] ;
19
20
@@ -30,11 +31,13 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
30
31
31
32
function getEditsForAction ( context : RefactorContext , actionName : string ) : RefactorEditInfo | undefined {
32
33
const { file, startPosition } = context ;
33
- const node = getTokenAtPosition ( file , startPosition ) ;
34
+ let node = getTokenAtPosition ( file , startPosition ) ;
34
35
35
36
switch ( actionName ) {
36
37
case toTemplateLiteralActionName :
38
+ if ( isParenthesizedExpression ( node . parent ) && isBinaryExpression ( node . parent . parent ) ) node = node . parent . parent ;
37
39
const maybeBinary = getParentBinaryExpression ( node ) ;
40
+
38
41
const arrayOfNodes = treeToArray ( maybeBinary ) [ 0 ] ;
39
42
const templateLiteral = nodesToTemplate ( arrayOfNodes ) ;
40
43
const edits = textChanges . ChangeTracker . with ( context , t => t . replaceNode ( file , maybeBinary , templateLiteral ) ) ;
@@ -78,15 +81,6 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
78
81
return expr ;
79
82
}
80
83
81
- function containsString ( node : Node ) : boolean {
82
- if ( isBinaryExpression ( node ) ) {
83
- return containsString ( node . left ) || containsString ( node . right ) ;
84
- }
85
-
86
- if ( isStringLiteral ( node ) ) return true ;
87
- return false ;
88
- }
89
-
90
84
function arrayToTree ( nodes : Expression [ ] , bexpr : BinaryExpression | undefined ) : BinaryExpression {
91
85
if ( nodes . length === 0 ) return bexpr ! ;
92
86
0 commit comments