@@ -566,6 +566,8 @@ namespace ts {
566566 return emitNode && emitNode . flags || 0 ;
567567 }
568568
569+ const escapeNoSubstitutionTemplateLiteralText = compose ( escapeString , escapeTemplateSubstitution ) ;
570+ const escapeNonAsciiNoSubstitutionTemplateLiteralText = compose ( escapeNonAsciiString , escapeTemplateSubstitution ) ;
569571 export function getLiteralText ( node : LiteralLikeNode , sourceFile : SourceFile , neverAsciiEscape : boolean | undefined ) {
570572 // If we don't need to downlevel and we can reach the original source text using
571573 // the node's parent reference, then simply get the text as it was originally written.
@@ -576,7 +578,11 @@ namespace ts {
576578 return getSourceTextOfNodeFromSourceFile ( sourceFile , node ) ;
577579 }
578580
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 ;
580586
581587 // If we can't reach the original source text, use the canonical form if it's a number,
582588 // or a (possibly escaped) quoted form of the original text if it's string-like.
@@ -3113,6 +3119,11 @@ namespace ts {
31133119 }
31143120 }
31153121
3122+ const templateSubstitutionRegExp = / \$ \{ / g;
3123+ function escapeTemplateSubstitution ( str : string ) : string {
3124+ return str . replace ( templateSubstitutionRegExp , "\\${" ) ;
3125+ }
3126+
31163127 // This consists of the first 19 unprintable ASCII characters, canonical escapes, lineSeparator,
31173128 // paragraphSeparator, and nextLine. The latter three are just desirable to suppress new lines in
31183129 // the language service. These characters should be escaped when printing, and if any characters are added,
0 commit comments