@@ -566,6 +566,8 @@ namespace ts {
566
566
return emitNode && emitNode . flags || 0 ;
567
567
}
568
568
569
+ const escapeNoSubstitutionTemplateLiteralText = compose ( escapeString , escapeTemplateSubstitution ) ;
570
+ const escapeNonAsciiNoSubstitutionTemplateLiteralText = compose ( escapeNonAsciiString , escapeTemplateSubstitution ) ;
569
571
export function getLiteralText ( node : LiteralLikeNode , sourceFile : SourceFile , neverAsciiEscape : boolean | undefined ) {
570
572
// If we don't need to downlevel and we can reach the original source text using
571
573
// the node's parent reference, then simply get the text as it was originally written.
@@ -576,7 +578,11 @@ namespace ts {
576
578
return getSourceTextOfNodeFromSourceFile ( sourceFile , node ) ;
577
579
}
578
580
579
- const escapeText = neverAsciiEscape || ( getEmitFlags ( node ) & EmitFlags . NoAsciiEscaping ) ? escapeString : escapeNonAsciiString ;
581
+ // If a NoSubstitutionTemplateLiteral appears to have a substitution in it, the original text
582
+ // had to include a backslash: `not \${a} substitution`.
583
+ const escapeText = neverAsciiEscape || ( getEmitFlags ( node ) & EmitFlags . NoAsciiEscaping ) ?
584
+ node . kind === SyntaxKind . NoSubstitutionTemplateLiteral ? escapeNoSubstitutionTemplateLiteralText : escapeString :
585
+ node . kind === SyntaxKind . NoSubstitutionTemplateLiteral ? escapeNonAsciiNoSubstitutionTemplateLiteralText : escapeNonAsciiString ;
580
586
581
587
// If we can't reach the original source text, use the canonical form if it's a number,
582
588
// or a (possibly escaped) quoted form of the original text if it's string-like.
@@ -3113,6 +3119,11 @@ namespace ts {
3113
3119
}
3114
3120
}
3115
3121
3122
+ const templateSubstitutionRegExp = / \$ \{ / g;
3123
+ function escapeTemplateSubstitution ( str : string ) : string {
3124
+ return str . replace ( templateSubstitutionRegExp , "\\${" ) ;
3125
+ }
3126
+
3116
3127
// This consists of the first 19 unprintable ASCII characters, canonical escapes, lineSeparator,
3117
3128
// paragraphSeparator, and nextLine. The latter three are just desirable to suppress new lines in
3118
3129
// the language service. These characters should be escaped when printing, and if any characters are added,
0 commit comments