Skip to content

Commit

Permalink
remove useless slash-escapes of non-ascii characters. Closes #1506
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosantoscode committed Mar 28, 2024
1 parent 1161ff1 commit 1306a72
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/parse.js
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions test/compress/regexp.js
Expand Up @@ -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 = {
Expand Down

0 comments on commit 1306a72

Please sign in to comment.