fix corner case in parsing private field/method (#4952)

fixes #4951
This commit is contained in:
Alex Lam S.L
2021-05-22 03:12:37 +01:00
committed by GitHub
parent de376c3d33
commit d2a45ba441
3 changed files with 34 additions and 7 deletions

View File

@@ -124,7 +124,7 @@ var PUNC_AFTER_EXPRESSION = PUNC_SEPARATORS + PUNC_CLOSERS;
var PUNC_BEFORE_EXPRESSION = PUNC_OPENERS + PUNC_SEPARATORS;
var PUNC_CHARS = PUNC_BEFORE_EXPRESSION + "`" + PUNC_CLOSERS;
var WHITESPACE_CHARS = NEWLINE_CHARS + " \u00a0\t\f\u000b\u200b\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\uFEFF";
var NON_IDENTIFIER_CHARS = makePredicate(characters("./'\"" + OPERATOR_CHARS + PUNC_CHARS + WHITESPACE_CHARS));
var NON_IDENTIFIER_CHARS = makePredicate(characters("./'\"#" + OPERATOR_CHARS + PUNC_CHARS + WHITESPACE_CHARS));
NEWLINE_CHARS = makePredicate(characters(NEWLINE_CHARS));
OPERATOR_CHARS = makePredicate(characters(OPERATOR_CHARS));
@@ -468,7 +468,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
});
function read_name() {
var backslash = false, name = "", ch, escaped = false, hex;
var backslash = false, ch, escaped = false, name = peek() == "#" ? next() : "";
while (ch = peek()) {
if (!backslash) {
if (ch == "\\") escaped = backslash = true, next();
@@ -483,7 +483,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
}
}
if (KEYWORDS[name] && escaped) {
hex = name.charCodeAt(0).toString(16).toUpperCase();
var hex = name.charCodeAt(0).toString(16).toUpperCase();
name = "\\u" + "0000".substr(hex.length) + hex + name.slice(1);
}
return name;
@@ -618,7 +618,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
if (PUNC_CHARS[ch]) return token("punc", next());
if (looking_at("=>")) return token("punc", next() + next());
if (OPERATOR_CHARS[ch]) return read_operator();
if (code == 92 || !NON_IDENTIFIER_CHARS[ch]) return read_word();
if (code == 35 || code == 92 || !NON_IDENTIFIER_CHARS[ch]) return read_word();
break;
}
parse_error("Unexpected character '" + ch + "'");