From 73fcbbb0eee6c549c63d4294b02d1e2da7353fe6 Mon Sep 17 00:00:00 2001 From: davidot Date: Thu, 17 Nov 2022 10:26:27 +0100 Subject: [PATCH] LibJS: Give the undeclared private identifier error more precedence Before this could give the `must be followed by in` error before the undeclared private identifier error. Fixing the `in` error would not have resolved the other error so this order makes the errors more actionable. --- Userland/Libraries/LibJS/Parser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 7af6cd93e7..4fb31c0c2b 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -1520,10 +1520,10 @@ Parser::PrimaryExpressionParseResult Parser::parse_primary_expression() goto read_as_identifier; return { parse_await_expression() }; case TokenType::PrivateIdentifier: - if (next_token().type() != TokenType::In) - syntax_error("Cannot have a private identifier in expression if not followed by 'in'"); if (!is_private_identifier_valid()) syntax_error(String::formatted("Reference to undeclared private field or method '{}'", m_state.current_token.value())); + if (next_token().type() != TokenType::In) + syntax_error("Cannot have a private identifier in expression if not followed by 'in'"); return { create_ast_node({ m_state.current_token.filename(), rule_start.position(), position() }, consume().value()) }; default: if (match_identifier_name())