Skip to content

Commit

Permalink
support ascii_only in template strings (#5911)
Browse files Browse the repository at this point in the history
closes #5910
  • Loading branch information
alexlamsl authored Aug 7, 2024
1 parent 2255074 commit 4661b34
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -1788,12 +1788,12 @@ function OutputStream(options) {
if (self.tag) self.tag.print(output);
output.print("`");
for (var i = 0; i < self.expressions.length; i++) {
output.print(self.strings[i]);
output.print(output.to_utf8(self.strings[i]));
output.print("${");
self.expressions[i].print(output);
output.print("}");
}
output.print(self.strings[i]);
output.print(output.to_utf8(self.strings[i]));
output.print("`");
});
DEFPRINT(AST_BigInt, function(output) {
Expand Down
64 changes: 64 additions & 0 deletions test/compress/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,70 @@ pure_funcs: {
node_version: ">=4"
}

ascii_only: {
beautify = {
ascii_only: true,
}
options = {
templates: false,
}
input: {
console.log(`\ud801\udc37\ud801𐐷${42}\u{10437}`);
}
expect_exact: "console.log(`\\ud801\\udc37\\ud801\\ud801\\udc37${42}\\u{10437}`);"
expect_stdout: "𐐷\ud801𐐷42𐐷"
// non-BMP support is platform-dependent on Node.js v4
node_version: ">=6"
}

ascii_only_templates: {
beautify = {
ascii_only: true,
}
options = {
templates: true,
}
input: {
console.log(`\ud801\udc37\ud801𐐷${42}\u{10437}`);
}
expect_exact: "console.log(`\\ud801\\udc37\\ud801\\ud801\\udc37${42}\\ud801\\udc37`);"
expect_stdout: "𐐷\ud801𐐷42𐐷"
// non-BMP support is platform-dependent on Node.js v4
node_version: ">=6"
}

unicode: {
beautify = {
ascii_only: false,
}
options = {
templates: false,
}
input: {
console.log(`\ud801\udc37\ud801𐐷${42}\u{10437}`);
}
expect_exact: "console.log(`\\ud801\\udc37\\ud801𐐷${42}\\u{10437}`);"
expect_stdout: "𐐷\ud801𐐷42𐐷"
// non-BMP support is platform-dependent on Node.js v4
node_version: ">=6"
}

unicode_templates: {
beautify = {
ascii_only: false,
}
options = {
templates: true,
}
input: {
console.log(`\ud801\udc37\ud801𐐷${42}\u{10437}`);
}
expect_exact: "console.log(`𐐷\\ud801𐐷${42}𐐷`);"
expect_stdout: "𐐷\ud801𐐷42𐐷"
// non-BMP support is platform-dependent on Node.js v4
node_version: ">=6"
}

issue_4604: {
options = {
collapse_vars: true,
Expand Down

0 comments on commit 4661b34

Please sign in to comment.