summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Parser.cpp35
-rw-r--r--Userland/Libraries/LibJS/Parser.h5
2 files changed, 36 insertions, 4 deletions
diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp
index fb6795d516..779783106d 100644
--- a/Userland/Libraries/LibJS/Parser.cpp
+++ b/Userland/Libraries/LibJS/Parser.cpp
@@ -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;
diff --git a/Userland/Libraries/LibJS/Parser.h b/Userland/Libraries/LibJS/Parser.h
index 97036c8de6..eaf9df0a94 100644
--- a/Userland/Libraries/LibJS/Parser.h
+++ b/Userland/Libraries/LibJS/Parser.h
@@ -159,8 +159,9 @@ private:
bool match_secondary_expression(const Vector<TokenType>& forbidden = {}) const;
bool match_statement() const;
bool match_export_or_import() const;
- bool match_declaration() const;
- bool match_variable_declaration() const;
+ bool match_declaration();
+ bool try_match_let_declaration();
+ bool match_variable_declaration();
bool match_identifier() const;
bool match_identifier_name() const;
bool match_property_key() const;