Skip to content

Commit

Permalink
parse extended Unicode literal correctly (#4792)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Mar 17, 2021
1 parent 997d09b commit 9fc0ff5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/parse.js
Expand Up @@ -161,10 +161,10 @@ function decode_escape_sequence(seq) {
case "t": return "\t";
case "u":
var code;
if (seq.length == 5) {
code = seq.slice(1);
} else if (seq[1] == "{" && seq.slice(-1) == "}") {
if (seq[1] == "{" && seq.slice(-1) == "}") {
code = seq.slice(2, -1);
} else if (seq.length == 5) {
code = seq.slice(1);
} else {
return;
}
Expand Down
13 changes: 12 additions & 1 deletion test/compress/unicode.js
Expand Up @@ -50,7 +50,7 @@ unicode_parse_variables: {
}
}

unicode_escaped_identifier: {
unicode_escaped_identifier_1: {
input: {
var \u0061 = "\ud800\udc00";
console.log(a);
Expand All @@ -59,6 +59,17 @@ unicode_escaped_identifier: {
expect_stdout: "\ud800\udc00"
}

unicode_escaped_identifier_2: {
input: {
var \u{61} = "foo";
var \u{10000} = "bar";
console.log(a, \u{10000});
}
expect_exact: 'var a="foo";var \u{10000}="bar";console.log(a,\u{10000});'
expect_stdout: "foo bar"
node_version: ">=4"
}

unicode_identifier_ascii_only: {
beautify = {
ascii_only: true,
Expand Down

0 comments on commit 9fc0ff5

Please sign in to comment.