diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go index 1bd17cc6c6..7322d9d56e 100644 --- a/internal/printer/printer_test.go +++ b/internal/printer/printer_test.go @@ -28,6 +28,7 @@ func TestEmit(t *testing.T) { {title: "BooleanLiteral#1", input: `true`, output: `true;`}, {title: "BooleanLiteral#2", input: `false`, output: `false;`}, {title: "NoSubstitutionTemplateLiteral", input: "``", output: "``;"}, + {title: "NoSubstitutionTemplateLiteral with newline", input: "`\n`", output: "`\n`;"}, {title: "RegularExpressionLiteral#1", input: `/a/`, output: `/a/;`}, {title: "RegularExpressionLiteral#2", input: `/a/g`, output: `/a/g;`}, {title: "NullLiteral", input: `null`, output: `null;`}, diff --git a/internal/printer/utilities_test.go b/internal/printer/utilities_test.go index cbe034f22d..c22a490b2f 100644 --- a/internal/printer/utilities_test.go +++ b/internal/printer/utilities_test.go @@ -25,6 +25,10 @@ func TestEscapeString(t *testing.T) { {s: "ab'c", quoteChar: QuoteCharSingleQuote, expected: `ab\'c`}, {s: "ab\"c", quoteChar: QuoteCharSingleQuote, expected: `ab"c`}, {s: "ab`c", quoteChar: QuoteCharBacktick, expected: "ab\\`c"}, + // Test template string newline preservation (from TypeScript PR #60303) + {s: "ab\nc", quoteChar: QuoteCharBacktick, expected: "ab\nc"}, + {s: "ab\nc", quoteChar: QuoteCharDoubleQuote, expected: "ab\\nc"}, + {s: "ab\nc", quoteChar: QuoteCharSingleQuote, expected: "ab\\nc"}, } for i, rec := range data { t.Run(fmt.Sprintf("[%d] escapeString(%q, %v)", i, rec.s, rec.quoteChar), func(t *testing.T) {