@@ -9,21 +9,21 @@ 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 = tag `aaa`;
13
12
14
13
registerRefactor ( refactorName , { getEditsForAction, getAvailableActions } ) ;
15
14
16
15
function getAvailableActions ( context : RefactorContext ) : ReadonlyArray < ApplicableRefactorInfo > {
17
16
const { file, startPosition } = context ;
18
17
const node = getTokenAtPosition ( file , startPosition ) ;
19
18
const maybeBinary = getParentBinaryExpression ( node ) ; containsString ( maybeBinary ) ;
19
+ const maybeTemplateExpression = findAncestor ( node , n => isTemplateExpression ( n ) ) ;
20
20
const actions : RefactorActionInfo [ ] = [ ] ;
21
21
22
22
if ( ( isBinaryExpression ( maybeBinary ) || isStringLiteral ( maybeBinary ) ) && containsString ( maybeBinary ) ) {
23
23
actions . push ( { name : toTemplateLiteralActionName , description : toTemplateLiteralDescription } ) ;
24
24
}
25
25
26
- if ( isNoSubstitutionTemplateLiteral ( node ) || isTemplateHead ( node ) || isTemplateSpan ( node . parent ) ) {
26
+ if ( ( isNoSubstitutionTemplateLiteral ( node ) && ! isTaggedTemplateExpression ( node . parent ) ) || ( maybeTemplateExpression && ! isTaggedTemplateExpression ( maybeTemplateExpression . parent ) ) ) {
27
27
actions . push ( { name : toStringConcatenationActionName , description : toStringConcatenationDescription } ) ;
28
28
}
29
29
@@ -46,8 +46,7 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
46
46
case toStringConcatenationActionName :
47
47
if ( isNoSubstitutionTemplateLiteral ( node ) ) {
48
48
const stringLiteral = createStringLiteral ( node . text ) ;
49
-
50
- return { edits : textChanges . ChangeTracker . with ( context , t => t . replaceNode ( file , node , stringLiteral ) ) } ;
49
+ return { edits : textChanges . ChangeTracker . with ( context , t => t . replaceNode ( file , node , stringLiteral ) ) } ;
51
50
52
51
}
53
52
if ( isTemplateExpression ( node . parent ) || isTemplateSpan ( node . parent ) ) {
0 commit comments