Port TypeScript PR #60303: Fix template string escaping - Analysis and Tests #1125
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses the porting of TypeScript PR #60303 which fixes template string escaping to preserve newlines in template literals. After thorough analysis, I found that this fix is already correctly implemented in the Go codebase.
Analysis of TypeScript PR #60303
The TypeScript fix changed the regular expression for backtick-quoted characters from:
This change excludes
\u000A
(newline character) from being escaped in template strings, preserving simple LF newlines while still escaping other control characters.Go Implementation Status
The Go code in
internal/printer/utilities.go
already implements this fix correctly:When the quote character is a backtick (template string), newlines are not escaped, which is exactly what the TypeScript fix achieved.
Changes Made
ab\nc
with backticks →ab\nc
(unescaped)ab\nc
with quotes →ab\\nc
(escaped)Test Results
Conclusion
No code changes were required as the Go implementation already correctly handles template string escaping as intended by TypeScript PR #60303. This PR adds tests to document and verify this behavior.
Fixes #1121.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
api.github.com
curl -s REDACTED
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.