Skip to content

Commit e6ef279

Browse files
authored
Fix template string escaping (#60303)
1 parent df9d165 commit e6ef279

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6064,7 +6064,7 @@ export function hasInvalidEscape(template: TemplateLiteral): boolean {
60646064
const doubleQuoteEscapedCharsRegExp = /[\\"\u0000-\u001f\u2028\u2029\u0085]/g;
60656065
const singleQuoteEscapedCharsRegExp = /[\\'\u0000-\u001f\u2028\u2029\u0085]/g;
60666066
// Template strings preserve simple LF newlines, still encode CRLF (or CR)
6067-
const backtickQuoteEscapedCharsRegExp = /\r\n|[\\`\u0000-\u001f\u2028\u2029\u0085]/g;
6067+
const backtickQuoteEscapedCharsRegExp = /\r\n|[\\`\u0000-\u0009\u000b-\u001f\u2028\u2029\u0085]/g;
60686068
const escapedCharsMap = new Map(Object.entries({
60696069
"\t": "\\t",
60706070
"\v": "\\v",

src/testRunner/unittests/printer.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,5 +358,13 @@ describe("unittests:: PrinterAPI", () => {
358358
),
359359
ts.createSourceFile("source.ts", "", ts.ScriptTarget.ES2015),
360360
));
361+
362+
// https://github.com/microsoft/TypeScript/issues/59150
363+
printsCorrectly("template string", {}, printer =>
364+
printer.printNode(
365+
ts.EmitHint.Unspecified,
366+
ts.factory.createNoSubstitutionTemplateLiteral("\n"),
367+
ts.createSourceFile("source.ts", "", ts.ScriptTarget.ESNext),
368+
));
361369
});
362370
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`
2+
`

0 commit comments

Comments
 (0)