summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-07-11 23:30:55 +0430
committerLinus Groh <mail@linusgroh.de>2021-07-11 21:41:54 +0100
commitdfb7e716f74d43c0996622d25cdda921926af7f3 (patch)
treee19cf260f0ed5de7927a4acad5425fd6ab4a40b9
parent049e210cface673abcb7ceaf9b192b9de16cb856 (diff)
downloadserenity-dfb7e716f74d43c0996622d25cdda921926af7f3.zip
LibJS: Use expected() instead of syntax_error("Expected ...")
-rw-r--r--Userland/Libraries/LibJS/Parser.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp
index 3adb8c6b48..70eda3e757 100644
--- a/Userland/Libraries/LibJS/Parser.cpp
+++ b/Userland/Libraries/LibJS/Parser.cpp
@@ -934,7 +934,7 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression()
if (property_type == ObjectProperty::Type::Getter || property_type == ObjectProperty::Type::Setter) {
if (!match(TokenType::ParenOpen)) {
- syntax_error("Expected '(' for object getter or setter property");
+ expected("'(' for object getter or setter property");
skip_to_next_property();
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));
} else if (match(TokenType::Colon)) {
if (!property_name) {
- syntax_error("Expected a property name");
+ expected("a property name");
skip_to_next_property();
continue;
}
@@ -968,7 +968,7 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression()
} 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));
} else {
- syntax_error("Expected a property");
+ expected("a property");
skip_to_next_property();
continue;
}
@@ -1706,7 +1706,7 @@ RefPtr<BindingPattern> Parser::parse_binding_pattern()
name = parse_expression(0);
consume(TokenType::BracketClose);
} else {
- syntax_error("Expected identifier or computed property name");
+ expected("identifier or computed property name");
return {};
}
@@ -1722,7 +1722,7 @@ RefPtr<BindingPattern> Parser::parse_binding_pattern()
{ m_state.current_token.filename(), rule_start.position(), position() },
consume().value());
} else {
- syntax_error("Expected identifier or binding pattern");
+ expected("identifier or binding pattern");
return {};
}
}
@@ -1735,12 +1735,12 @@ RefPtr<BindingPattern> Parser::parse_binding_pattern()
} else if (match(TokenType::BracketOpen) || match(TokenType::CurlyOpen)) {
auto pattern = parse_binding_pattern();
if (!pattern) {
- syntax_error("Expected binding pattern");
+ expected("binding pattern");
return {};
}
alias = pattern.release_nonnull();
} else {
- syntax_error("Expected identifier or binding pattern");
+ expected("identifier or binding pattern");
return {};
}
}
@@ -1755,7 +1755,7 @@ RefPtr<BindingPattern> Parser::parse_binding_pattern()
initializer = parse_expression(2);
if (!initializer) {
- syntax_error("Expected initialization expression");
+ expected("initialization expression");
return {};
}
}
@@ -1831,7 +1831,7 @@ NonnullRefPtr<VariableDeclaration> Parser::parse_variable_declaration(bool for_l
}
if (target.has<Empty>()) {
- syntax_error("Expected an identifier or a binding pattern");
+ expected("identifier or a binding pattern");
if (match(TokenType::Comma)) {
consume();
continue;
@@ -2108,7 +2108,7 @@ NonnullRefPtr<CatchClause> Parser::parse_catch_clause()
}
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)
pattern_parameter->for_each_bound_name([this](auto& name) { check_identifier_name_for_assignment_validity(name); });