瀏覽代碼

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.
davidot 2 年之前
父節點
當前提交
73fcbbb0ee
共有 1 個文件被更改,包括 2 次插入2 次删除
  1. 2 2
      Userland/Libraries/LibJS/Parser.cpp

+ 2 - 2
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<PrivateIdentifier>({ m_state.current_token.filename(), rule_start.position(), position() }, consume().value()) };
     default:
         if (match_identifier_name())