diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 64be5c4f7eba9..c3a839639bffd 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -6064,7 +6064,7 @@ export function hasInvalidEscape(template: TemplateLiteral): boolean { const doubleQuoteEscapedCharsRegExp = /[\\"\u0000-\u001f\u2028\u2029\u0085]/g; const singleQuoteEscapedCharsRegExp = /[\\'\u0000-\u001f\u2028\u2029\u0085]/g; // Template strings preserve simple LF newlines, still encode CRLF (or CR) -const backtickQuoteEscapedCharsRegExp = /\r\n|[\\`\u0000-\u001f\u2028\u2029\u0085]/g; +const backtickQuoteEscapedCharsRegExp = /\r\n|[\\`\u0000-\u0009\u000b-\u001f\u2028\u2029\u0085]/g; const escapedCharsMap = new Map(Object.entries({ "\t": "\\t", "\v": "\\v", diff --git a/src/testRunner/unittests/printer.ts b/src/testRunner/unittests/printer.ts index 2e44c6cb73a3c..cff0ce2e47f3e 100644 --- a/src/testRunner/unittests/printer.ts +++ b/src/testRunner/unittests/printer.ts @@ -358,5 +358,13 @@ describe("unittests:: PrinterAPI", () => { ), ts.createSourceFile("source.ts", "", ts.ScriptTarget.ES2015), )); + + // https://github.com/microsoft/TypeScript/issues/59150 + printsCorrectly("template string", {}, printer => + printer.printNode( + ts.EmitHint.Unspecified, + ts.factory.createNoSubstitutionTemplateLiteral("\n"), + ts.createSourceFile("source.ts", "", ts.ScriptTarget.ESNext), + )); }); }); diff --git a/tests/baselines/reference/printerApi/printsNodeCorrectly.template string.js b/tests/baselines/reference/printerApi/printsNodeCorrectly.template string.js new file mode 100644 index 0000000000000..7acaf247a15a0 --- /dev/null +++ b/tests/baselines/reference/printerApi/printsNodeCorrectly.template string.js @@ -0,0 +1,2 @@ +` +` \ No newline at end of file