@@ -15,20 +15,28 @@ namespace ts.refactor.convertStringOrTemplateLiteral {
15
15
let node = getTokenAtPosition ( file , startPosition ) ;
16
16
if ( isParenthesizedExpression ( node . parent ) && isBinaryExpression ( node . parent . parent ) ) node = node . parent . parent ;
17
17
const maybeBinary = getParentBinaryExpression ( node ) ;
18
- const maybeTemplateExpression = findAncestor ( node , n => isTemplateExpression ( n ) ) ;
18
+ // const maybeTemplateExpression = findAncestor(node, n => isTemplateExpression(n));
19
19
const actions : RefactorActionInfo [ ] = [ ] ;
20
20
21
21
if ( ( isBinaryExpression ( maybeBinary ) || isStringLiteral ( maybeBinary ) ) && isStringConcatenationValid ( maybeBinary ) ) {
22
22
actions . push ( { name : toTemplateLiteralActionName , description : toTemplateLiteralDescription } ) ;
23
23
}
24
24
25
- if ( ( isNoSubstitutionTemplateLiteral ( node ) && ! isTaggedTemplateExpression ( node . parent ) ) || ( maybeTemplateExpression && ! isTaggedTemplateExpression ( maybeTemplateExpression . parent ) ) ) {
25
+ // if ((isNoSubstitutionTemplateLiteral(node) && !isTaggedTemplateExpression(node.parent)) || (maybeTemplateExpression && !isTaggedTemplateExpression(maybeTemplateExpression.parent))) {
26
+ if ( isTemplateLike ( node ) ) {
26
27
actions . push ( { name : toStringConcatenationActionName , description : toStringConcatenationDescription } ) ;
27
28
}
28
29
29
30
return [ { name : refactorName , description : refactorDescription , actions } ] ;
30
31
}
31
32
33
+ function isTemplateLike ( node : Node ) {
34
+ const isEmptyTL = isNoSubstitutionTemplateLiteral ( node ) && ! isTaggedTemplateExpression ( node . parent ) ;
35
+ const is = ( isTemplateHead ( node ) || isTemplateMiddleOrTemplateTail ( node ) ) && ! isTaggedTemplateExpression ( node . parent . parent ) ;
36
+ const ise = ( isTemplateSpan ( node . parent ) ) && ! isTaggedTemplateExpression ( node . parent . parent . parent ) ;
37
+ return isEmptyTL || is || ise ;
38
+ }
39
+
32
40
function getEditsForAction ( context : RefactorContext , actionName : string ) : RefactorEditInfo | undefined {
33
41
const { file, startPosition } = context ;
34
42
let node = getTokenAtPosition ( file , startPosition ) ;
0 commit comments