Skip to content

Commit

Permalink
Fix template string escaping (#60303)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton authored Oct 21, 2024
1 parent df9d165 commit e6ef279
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions src/testRunner/unittests/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
));
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`
`

0 comments on commit e6ef279

Please sign in to comment.