Skip to content

Commit

Permalink
do not emit unicode code point escapes inside RegExp literals. Closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosantoscode committed Feb 19, 2022
1 parent 748e0e8 commit c2e550f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/output.js
Expand Up @@ -285,8 +285,8 @@ function OutputStream(options) {
var OUTPUT = new Rope();
let printed_comments = new Set();

var to_utf8 = options.ascii_only ? function(str, identifier) {
if (options.ecma >= 2015 && !options.safari10) {
var to_utf8 = options.ascii_only ? function(str, identifier = false, regexp = false) {
if (options.ecma >= 2015 && !options.safari10 && !regexp) {
str = str.replace(/[\ud800-\udbff][\udc00-\udfff]/g, function(ch) {
var code = get_full_char_code(ch, 0).toString(16);
return "\\u{" + code + "}";
Expand Down Expand Up @@ -2213,7 +2213,7 @@ function OutputStream(options) {
flags = flags ? sort_regexp_flags(flags) : "";
source = source.replace(r_slash_script, slash_script_replace);

output.print(output.to_utf8(`/${source}/${flags}`));
output.print(output.to_utf8(`/${source}/${flags}`, false, true));

const parent = output.parent();
if (
Expand Down
2 changes: 1 addition & 1 deletion test/compress.js
Expand Up @@ -100,7 +100,7 @@ async function run_compress_tests() {
log_start_file(file);
async function test_case(test) {
log_test(test.name);
var output_options = test.beautify || {};
var output_options = test.beautify || test.format || {};
var expect;
if (test.expect) {
expect = make_code(as_toplevel(test.expect, test.mangle), output_options);
Expand Down
13 changes: 13 additions & 0 deletions test/compress/unicode.js
Expand Up @@ -189,3 +189,16 @@ issue_3271: {
}
expect_stdout: "[ 195, 169 ]"
}

issue_1147: {
format = {
ecma: 2015,
ascii_only: true,
safari10: false
}
input: {
console.log(/📞/.test("📞"))
}
expect_exact: 'console.log(/\\ud83d\\udcde/.test("\\u{1f4de}"));'
expect_stdout: "true"
}

0 comments on commit c2e550f

Please sign in to comment.