1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:28:10 +00:00

LibJS: Force the lexer to parse a regex when expecting a statement

This commit is contained in:
davidot 2021-07-29 23:28:28 +02:00 committed by Linus Groh
parent 05444103e3
commit 106f9e30d7
4 changed files with 103 additions and 21 deletions

View file

@ -400,6 +400,10 @@ NonnullRefPtr<Statement> Parser::parse_statement(AllowLabelledFunction allow_lab
case TokenType::Semicolon:
consume();
return create_ast_node<EmptyStatement>({ m_state.current_token.filename(), rule_start.position(), position() });
case TokenType::Slash:
case TokenType::SlashEquals:
m_state.current_token = m_state.lexer.force_slash_as_regex();
[[fallthrough]];
default:
if (match_identifier_name()) {
auto result = try_parse_labelled_statement(allow_labelled_function);
@ -2556,6 +2560,8 @@ bool Parser::match_expression() const
|| type == TokenType::This
|| type == TokenType::Super
|| type == TokenType::RegexLiteral
|| type == TokenType::Slash // Wrongly recognized regex by lexer
|| type == TokenType::SlashEquals // Wrongly recognized regex by lexer (/=a/ is a valid regex)
|| type == TokenType::Yield
|| match_unary_prefixed_expression();
}