Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Output, to_ascii: Escape non-ascii chars with \xnn instead of \unnnn whenever possible #172

Closed
wants to merge 1 commit into from

2 participants

@papandreou

Previously ASCII-only mode was a bit wasteful:

$ uglifyjs --beautify ascii_only=true
alert("føø");
^D
alert("f\u00f8\u00f8");

With this patch the output is:

alert("f\xf8\xf8");
@mishoo
Owner

Merged this too, thanks.

@mishoo mishoo closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 31, 2013
  1. @papandreou
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/output.js
View
9 lib/output.js
@@ -72,8 +72,13 @@ function OutputStream(options) {
function to_ascii(str) {
return str.replace(/[\u0080-\uffff]/g, function(ch) {
var code = ch.charCodeAt(0).toString(16);
- while (code.length < 4) code = "0" + code;
- return "\\u" + code;
+ if (code.length <= 2) {
+ while (code.length < 2) code = "0" + code;
+ return "\\x" + code;
+ } else {
+ while (code.length < 4) code = "0" + code;
+ return "\\u" + code;
+ }
});
};
Something went wrong with that request. Please try again.