From 6d2b01ceb45e6f51de6db1a7edc3efbd70acaace Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Jun 2025 22:39:43 +0000 Subject: [PATCH 1/2] Initial plan for issue From c5c16c7341df42e06b218deaa21fa9cce2a3c398 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Jun 2025 22:48:50 +0000 Subject: [PATCH 2/2] Add tests for template string newline preservation Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com> --- internal/printer/printer_test.go | 1 + internal/printer/utilities_test.go | 4 ++++ 2 files changed, 5 insertions(+) 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) {