@@ -9,6 +9,7 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
9
9
const toStringConcatenationDescription = getLocaleSpecificMessage ( Diagnostics . Convert_to_string_concatenation ) ;
10
10
11
11
// TODO let a = 45 + 45 + " ee" + 33;
12
+ // TODO let a = 45 - 45 + " ee" - 33;
12
13
// TODO let a = tag `aaa`;
13
14
14
15
registerRefactor ( refactorName , { getEditsForAction, getAvailableActions } ) ;
@@ -19,22 +20,17 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
19
20
const maybeBinary = getParentBinaryExpression ( node ) ; containsString ( maybeBinary ) ;
20
21
const actions : RefactorActionInfo [ ] = [ ] ;
21
22
22
- if ( ! isTemplateLike ( node ) && ( isBinaryExpression ( maybeBinary ) || isStringLiteral ( maybeBinary ) ) && containsString ( maybeBinary ) ) {
23
+ if ( ( isBinaryExpression ( maybeBinary ) || isStringLiteral ( maybeBinary ) ) && containsString ( maybeBinary ) ) {
23
24
actions . push ( { name : toTemplateLiteralActionName , description : toTemplateLiteralDescription } ) ;
24
25
}
25
26
26
-
27
- if ( isTemplateLike ( node ) ) {
27
+ if ( isNoSubstitutionTemplateLiteral ( node ) || isTemplateHead ( node ) || isTemplateSpan ( node . parent ) ) {
28
28
actions . push ( { name : toStringConcatenationActionName , description : toStringConcatenationDescription } ) ;
29
29
}
30
30
31
31
return [ { name : refactorName , description : refactorDescription , actions } ] ;
32
32
}
33
33
34
- function isTemplateLike ( node : Node ) : boolean {
35
- return isNoSubstitutionTemplateLiteral ( node ) || isTemplateHead ( node ) || isTemplateMiddleOrTemplateTail ( node ) ;
36
- }
37
-
38
34
function getEditsForAction ( context : RefactorContext , actionName : string ) : RefactorEditInfo | undefined {
39
35
const { file, startPosition } = context ;
40
36
const node = getTokenAtPosition ( file , startPosition ) ;
@@ -55,8 +51,8 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
55
51
return { edits : textChanges . ChangeTracker . with ( context , t => t . replaceNode ( file , node , stringLiteral ) ) } ;
56
52
57
53
}
58
- if ( isTemplateExpression ( node . parent ) ) {
59
- const templateLiteralExpression = node . parent ;
54
+ if ( isTemplateExpression ( node . parent ) || isTemplateSpan ( node . parent ) ) {
55
+ const templateLiteralExpression = isTemplateSpan ( node . parent ) ? node . parent . parent : node . parent ;
60
56
const nodesArray : Expression [ ] = [ ] ;
61
57
62
58
if ( templateLiteralExpression . head . text . length !== 0 ) nodesArray . push ( createStringLiteral ( templateLiteralExpression . head . text ) ) ;
0 commit comments