Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/printer/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ 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#2", input: "`\n`", output: "`\n`;"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was mistaken; this test passes even without this PR's change. Add a test which would have failed before this PR's fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test case for \u001f character in template literals that would have failed before this PR's fix. The test demonstrates that \u001f is now properly escaped to \u001F while preserving the correct behavior for \n (which should not be escaped). Commit fadf221.


{title: "RegularExpressionLiteral#1", input: `/a/`, output: `/a/;`},
{title: "RegularExpressionLiteral#2", input: `/a/g`, output: `/a/g;`},
{title: "NullLiteral", input: `null`, output: `null;`},
Expand Down
2 changes: 1 addition & 1 deletion internal/printer/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func escapeStringWorker(s string, quoteChar QuoteChar, flags getLiteralTextFlags
escape = true
}
default:
if ch < '\u001f' || flags&getLiteralTextFlagsNeverAsciiEscape == 0 && ch > '\u007f' {
if ch <= '\u001f' || flags&getLiteralTextFlagsNeverAsciiEscape == 0 && ch > '\u007f' {
escape = true
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/printer/utilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ 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"},
{s: "\u001f", quoteChar: QuoteCharBacktick, expected: "\\u001F"},
}
for i, rec := range data {
t.Run(fmt.Sprintf("[%d] escapeString(%q, %v)", i, rec.s, rec.quoteChar), func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
=== templateStringControlCharacterEscapes03.ts ===
var x = `\x1F\u001f 1F 1f`;
>x : string
>`\x1F\u001f 1F 1f` : " 1F 1f"
>`\x1F\u001f 1F 1f` : "\u001F\u001F 1F 1f"

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
=== templateStringControlCharacterEscapes03_ES6.ts ===
var x = `\x1F\u001f 1F 1f`;
>x : string
>`\x1F\u001f 1F 1f` : " 1F 1f"
>`\x1F\u001f 1F 1f` : "\u001F\u001F 1F 1f"

This file was deleted.