Skip to content

Commit 34a509b

Browse files
fix(javascript): read asciiOnly where a string's tabs are written raw
The printer's format options are camelCase since #23052, so the check #23051 added read an option that is never set, and ASCII-only output escaped the tabs of a long string it would otherwise write raw. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HArJAXZagrHVVNLZZk9soh
1 parent f65c027 commit 34a509b

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ class MinifiedOutput {
11251125
const rawTabs = quote !== "`" && writesTabsRaw(str);
11261126
// Where only ASCII is written a raw tab would be escaped again, so the
11271127
// tabs are unescaped once the rest is.
1128-
const tabsAsIs = rawTabs && !options.ascii_only;
1128+
const tabsAsIs = rawTabs && !options.asciiOnly;
11291129
let doubleQuotes = 0;
11301130
let singleQuotes = 0;
11311131
let escaped = "";

‎test/unitCases/javascript/printer.unittest.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,16 @@ describe("JavaScript minifier printing a SyntaxTree", () => {
12351235
);
12361236
});
12371237

1238+
it("should write a long string's tabs raw where only ASCII is written", () => {
1239+
// A tab is ASCII, so `asciiOnly` leaves the tabs of a string long enough
1240+
// to write them raw as they are, and escapes only what is past ASCII.
1241+
const text = `${"a\t".repeat(60)}é`;
1242+
const { code } = minifyOnePass(`g(${JSON.stringify(text)})`, {
1243+
format: { asciiOnly: true }
1244+
});
1245+
expect(code).toBe(`g("${"a\t".repeat(60)}\\xe9");`);
1246+
});
1247+
12381248
it("should print as the format options ask in the one pass", () => {
12391249
/** @type {[string, import("../../../lib/javascript/syntax-printer").MinifyOptions, string][]} */
12401250
const cases = [

0 commit comments

Comments
 (0)