mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 13:17:43 +00:00
LibJS: Use expected() instead of syntax_error("Expected ...")
This commit is contained in:
parent
049e210cfa
commit
dfb7e716f7
1 changed files with 10 additions and 10 deletions
|
@ -934,7 +934,7 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression()
|
||||||
|
|
||||||
if (property_type == ObjectProperty::Type::Getter || property_type == ObjectProperty::Type::Setter) {
|
if (property_type == ObjectProperty::Type::Getter || property_type == ObjectProperty::Type::Setter) {
|
||||||
if (!match(TokenType::ParenOpen)) {
|
if (!match(TokenType::ParenOpen)) {
|
||||||
syntax_error("Expected '(' for object getter or setter property");
|
expected("'(' for object getter or setter property");
|
||||||
skip_to_next_property();
|
skip_to_next_property();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -959,7 +959,7 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression()
|
||||||
properties.append(create_ast_node<ObjectProperty>({ m_state.current_token.filename(), rule_start.position(), position() }, *property_name, function, property_type, true));
|
properties.append(create_ast_node<ObjectProperty>({ m_state.current_token.filename(), rule_start.position(), position() }, *property_name, function, property_type, true));
|
||||||
} else if (match(TokenType::Colon)) {
|
} else if (match(TokenType::Colon)) {
|
||||||
if (!property_name) {
|
if (!property_name) {
|
||||||
syntax_error("Expected a property name");
|
expected("a property name");
|
||||||
skip_to_next_property();
|
skip_to_next_property();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -968,7 +968,7 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression()
|
||||||
} else if (property_name && property_value) {
|
} else if (property_name && property_value) {
|
||||||
properties.append(create_ast_node<ObjectProperty>({ m_state.current_token.filename(), rule_start.position(), position() }, *property_name, *property_value, property_type, false));
|
properties.append(create_ast_node<ObjectProperty>({ m_state.current_token.filename(), rule_start.position(), position() }, *property_name, *property_value, property_type, false));
|
||||||
} else {
|
} else {
|
||||||
syntax_error("Expected a property");
|
expected("a property");
|
||||||
skip_to_next_property();
|
skip_to_next_property();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1706,7 +1706,7 @@ RefPtr<BindingPattern> Parser::parse_binding_pattern()
|
||||||
name = parse_expression(0);
|
name = parse_expression(0);
|
||||||
consume(TokenType::BracketClose);
|
consume(TokenType::BracketClose);
|
||||||
} else {
|
} else {
|
||||||
syntax_error("Expected identifier or computed property name");
|
expected("identifier or computed property name");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1722,7 +1722,7 @@ RefPtr<BindingPattern> Parser::parse_binding_pattern()
|
||||||
{ m_state.current_token.filename(), rule_start.position(), position() },
|
{ m_state.current_token.filename(), rule_start.position(), position() },
|
||||||
consume().value());
|
consume().value());
|
||||||
} else {
|
} else {
|
||||||
syntax_error("Expected identifier or binding pattern");
|
expected("identifier or binding pattern");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1735,12 +1735,12 @@ RefPtr<BindingPattern> Parser::parse_binding_pattern()
|
||||||
} else if (match(TokenType::BracketOpen) || match(TokenType::CurlyOpen)) {
|
} else if (match(TokenType::BracketOpen) || match(TokenType::CurlyOpen)) {
|
||||||
auto pattern = parse_binding_pattern();
|
auto pattern = parse_binding_pattern();
|
||||||
if (!pattern) {
|
if (!pattern) {
|
||||||
syntax_error("Expected binding pattern");
|
expected("binding pattern");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
alias = pattern.release_nonnull();
|
alias = pattern.release_nonnull();
|
||||||
} else {
|
} else {
|
||||||
syntax_error("Expected identifier or binding pattern");
|
expected("identifier or binding pattern");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1755,7 +1755,7 @@ RefPtr<BindingPattern> Parser::parse_binding_pattern()
|
||||||
|
|
||||||
initializer = parse_expression(2);
|
initializer = parse_expression(2);
|
||||||
if (!initializer) {
|
if (!initializer) {
|
||||||
syntax_error("Expected initialization expression");
|
expected("initialization expression");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1831,7 +1831,7 @@ NonnullRefPtr<VariableDeclaration> Parser::parse_variable_declaration(bool for_l
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target.has<Empty>()) {
|
if (target.has<Empty>()) {
|
||||||
syntax_error("Expected an identifier or a binding pattern");
|
expected("identifier or a binding pattern");
|
||||||
if (match(TokenType::Comma)) {
|
if (match(TokenType::Comma)) {
|
||||||
consume();
|
consume();
|
||||||
continue;
|
continue;
|
||||||
|
@ -2108,7 +2108,7 @@ NonnullRefPtr<CatchClause> Parser::parse_catch_clause()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (should_expect_parameter && parameter.is_empty() && !pattern_parameter)
|
if (should_expect_parameter && parameter.is_empty() && !pattern_parameter)
|
||||||
syntax_error("Expected an identifier or a binding pattern");
|
expected("an identifier or a binding pattern");
|
||||||
|
|
||||||
if (pattern_parameter)
|
if (pattern_parameter)
|
||||||
pattern_parameter->for_each_bound_name([this](auto& name) { check_identifier_name_for_assignment_validity(name); });
|
pattern_parameter->for_each_bound_name([this](auto& name) { check_identifier_name_for_assignment_validity(name); });
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue