mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:17:36 +00:00
LibJS: Check that 'let' is followed by declaration before matching it
Since 'let' is a valid variable name (in non-strict mode) let may not be the start of a declaration but just an identifier.
This commit is contained in:
parent
179c48e1a4
commit
5f344f7ca3
2 changed files with 36 additions and 4 deletions
|
@ -2748,18 +2748,49 @@ bool Parser::match_export_or_import() const
|
|||
|| type == TokenType::Import;
|
||||
}
|
||||
|
||||
bool Parser::match_declaration() const
|
||||
bool Parser::match_declaration()
|
||||
{
|
||||
auto type = m_state.current_token.type();
|
||||
|
||||
if (type == TokenType::Let && !m_state.strict_mode) {
|
||||
return try_match_let_declaration();
|
||||
}
|
||||
|
||||
return type == TokenType::Function
|
||||
|| type == TokenType::Class
|
||||
|| type == TokenType::Const
|
||||
|| type == TokenType::Let;
|
||||
}
|
||||
|
||||
bool Parser::match_variable_declaration() const
|
||||
bool Parser::try_match_let_declaration()
|
||||
{
|
||||
VERIFY(m_state.current_token.type() == TokenType::Let);
|
||||
|
||||
save_state();
|
||||
|
||||
ScopeGuard state_rollback = [&] {
|
||||
load_state();
|
||||
};
|
||||
|
||||
consume(TokenType::Let);
|
||||
|
||||
if (match_identifier_name() && m_state.current_token.value() != "in"sv)
|
||||
return true;
|
||||
|
||||
if (match(TokenType::CurlyOpen) || match(TokenType::BracketOpen))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Parser::match_variable_declaration()
|
||||
{
|
||||
auto type = m_state.current_token.type();
|
||||
|
||||
if (type == TokenType::Let && !m_state.strict_mode) {
|
||||
return try_match_let_declaration();
|
||||
}
|
||||
|
||||
return type == TokenType::Var
|
||||
|| type == TokenType::Let
|
||||
|| type == TokenType::Const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue