diff --git a/lib/parse.js b/lib/parse.js index 0c0e622bb..786479c87 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -814,7 +814,12 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { while ((ch = next(true))) if (NEWLINE_CHARS.has(ch)) { parse_error("Unexpected line terminator"); } else if (prev_backslash) { - source += "\\" + ch; + if (/^[\u0000-\u007F]$/.test(ch)) { + source += "\\" + ch; + } else { + // Remove the useless slash before the escape, but only for characters that won't be added to regexp syntax + source += ch; + } prev_backslash = false; } else if (ch == "[") { in_class = true; diff --git a/test/compress/regexp.js b/test/compress/regexp.js index af31aaa85..d71b601be 100644 --- a/test/compress/regexp.js +++ b/test/compress/regexp.js @@ -63,6 +63,19 @@ unsafe_nul_byte: { } } +double_escape: { + format = { + ascii_only: true + } + input: { + /\🏳0\🌈️\☺/ + } + expect: { + /\ud83c\udff30\ud83c\udf08\ufe0f\u263a/ + } + expect_stdout: true +} + inline_script: { options = {} beautify = {