Skip to content

Commit

Permalink
[[FIX]] Support RegExp Unicode property escapes
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike committed Mar 1, 2021
1 parent f05c8d1 commit f14636b
Show file tree
Hide file tree
Showing 5 changed files with 677 additions and 807 deletions.
54 changes: 54 additions & 0 deletions src/lex.js
Expand Up @@ -1440,6 +1440,60 @@ Lexer.prototype = {
}
}

if (char === "p" || char === "P") {
var y = index + 2;
sequence = "";
next = "";

if (this.peek(index + 1) === "{") {
next = this.peek(y);
while (next && next !== "}") {
sequence += next;
y += 1;
next = this.peek(y);
}
}

// Module loading is intentionally deferred as an optimization for
// Node.js users who do not use Unicode escape sequences.
if (!sequence || !require("./validate-unicode-escape-sequence")(sequence)) {
this.triggerAsync(
"error",
{
code: "E016",
line: this.line,
character: this.char,
data: [ "Invalid Unicode property escape sequence" ]
},
checks,
hasUFlag
);
}

if (sequence) {
sequence = char + "{" + sequence + "}";
body += sequence;
value += sequence;
index = y + 1;

if (!state.inES9()) {
this.triggerAsync(
"warning",
{
code: "W119",
line: this.line,
character: this.char,
data: [ "Unicode property escape", "9" ]
},
checks,
hasUFlag
);
}

return sequence;
}
}

// Unexpected control character
if (char < " ") {
malformed = true;
Expand Down
2 changes: 1 addition & 1 deletion src/reg.js
Expand Up @@ -51,7 +51,7 @@ exports.regexpQuantifiers = /[*+?{]/;

exports.regexpControlEscapes = /[fnrtv]/;

exports.regexpCharClasses = /[dDsSwW]/;
exports.regexpCharClasses = /[dDsSwWpP]/;

// Identifies the "dot" atom in regular expressions
exports.regexpDot = /(^|[^\\])(\\\\)*\./;

0 comments on commit f14636b

Please sign in to comment.