1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:07:35 +00:00

LibJS: Use String::formatted() for parser error messages

This commit is contained in:
Linus Groh 2020-10-04 14:53:15 +01:00 committed by Andreas Kling
parent f9eaac62d9
commit bc701658f8
2 changed files with 8 additions and 8 deletions

View file

@ -658,7 +658,7 @@ NonnullRefPtr<Expression> Parser::parse_unary_prefixed_expression()
// FIXME: Apparently for functions this should also not be enforced on a parser level, // FIXME: Apparently for functions this should also not be enforced on a parser level,
// other engines throw ReferenceError for ++foo() // other engines throw ReferenceError for ++foo()
if (!rhs->is_identifier() && !rhs->is_member_expression()) if (!rhs->is_identifier() && !rhs->is_member_expression())
syntax_error(String::format("Right-hand side of prefix increment operator must be identifier or member expression, got %s", rhs->class_name()), rhs_start_line, rhs_start_column); syntax_error(String::formatted("Right-hand side of prefix increment operator must be identifier or member expression, got {}", rhs->class_name()), rhs_start_line, rhs_start_column);
return create_ast_node<UpdateExpression>(UpdateOp::Increment, move(rhs), true); return create_ast_node<UpdateExpression>(UpdateOp::Increment, move(rhs), true);
} }
case TokenType::MinusMinus: { case TokenType::MinusMinus: {
@ -669,7 +669,7 @@ NonnullRefPtr<Expression> Parser::parse_unary_prefixed_expression()
// FIXME: Apparently for functions this should also not be enforced on a parser level, // FIXME: Apparently for functions this should also not be enforced on a parser level,
// other engines throw ReferenceError for --foo() // other engines throw ReferenceError for --foo()
if (!rhs->is_identifier() && !rhs->is_member_expression()) if (!rhs->is_identifier() && !rhs->is_member_expression())
syntax_error(String::format("Right-hand side of prefix decrement operator must be identifier or member expression, got %s", rhs->class_name()), rhs_start_line, rhs_start_column); syntax_error(String::formatted("Right-hand side of prefix decrement operator must be identifier or member expression, got {}", rhs->class_name()), rhs_start_line, rhs_start_column);
return create_ast_node<UpdateExpression>(UpdateOp::Decrement, move(rhs), true); return create_ast_node<UpdateExpression>(UpdateOp::Decrement, move(rhs), true);
} }
case TokenType::ExclamationMark: case TokenType::ExclamationMark:
@ -856,7 +856,7 @@ NonnullRefPtr<StringLiteral> Parser::parse_string_literal(Token token)
String message; String message;
if (status == Token::StringValueStatus::MalformedHexEscape || status == Token::StringValueStatus::MalformedUnicodeEscape) { if (status == Token::StringValueStatus::MalformedHexEscape || status == Token::StringValueStatus::MalformedUnicodeEscape) {
auto type = status == Token::StringValueStatus::MalformedUnicodeEscape ? "unicode" : "hexadecimal"; auto type = status == Token::StringValueStatus::MalformedUnicodeEscape ? "unicode" : "hexadecimal";
message = String::format("Malformed %s escape sequence", type); message = String::formatted("Malformed {} escape sequence", type);
} else if (status == Token::StringValueStatus::UnicodeEscapeOverflow) { } else if (status == Token::StringValueStatus::UnicodeEscapeOverflow) {
message = "Unicode code_point must not be greater than 0x10ffff in escape sequence"; message = "Unicode code_point must not be greater than 0x10ffff in escape sequence";
} }
@ -1084,7 +1084,7 @@ NonnullRefPtr<Expression> Parser::parse_secondary_expression(NonnullRefPtr<Expre
auto name = static_cast<const Identifier&>(*lhs).string(); auto name = static_cast<const Identifier&>(*lhs).string();
if (name == "eval" || name == "arguments") { if (name == "eval" || name == "arguments") {
syntax_error( syntax_error(
String::format("'%s' cannot be assigned to in strict mode code", name.characters()), String::formatted("'{}' cannot be assigned to in strict mode code", name),
m_parser_state.m_current_token.line_number(), m_parser_state.m_current_token.line_number(),
m_parser_state.m_current_token.line_column()); m_parser_state.m_current_token.line_column());
} }
@ -1105,14 +1105,14 @@ NonnullRefPtr<Expression> Parser::parse_secondary_expression(NonnullRefPtr<Expre
// FIXME: Apparently for functions this should also not be enforced on a parser level, // FIXME: Apparently for functions this should also not be enforced on a parser level,
// other engines throw ReferenceError for foo()++ // other engines throw ReferenceError for foo()++
if (!lhs->is_identifier() && !lhs->is_member_expression()) if (!lhs->is_identifier() && !lhs->is_member_expression())
syntax_error(String::format("Left-hand side of postfix increment operator must be identifier or member expression, got %s", lhs->class_name())); syntax_error(String::formatted("Left-hand side of postfix increment operator must be identifier or member expression, got {}", lhs->class_name()));
consume(); consume();
return create_ast_node<UpdateExpression>(UpdateOp::Increment, move(lhs)); return create_ast_node<UpdateExpression>(UpdateOp::Increment, move(lhs));
case TokenType::MinusMinus: case TokenType::MinusMinus:
// FIXME: Apparently for functions this should also not be enforced on a parser level, // FIXME: Apparently for functions this should also not be enforced on a parser level,
// other engines throw ReferenceError for foo()-- // other engines throw ReferenceError for foo()--
if (!lhs->is_identifier() && !lhs->is_member_expression()) if (!lhs->is_identifier() && !lhs->is_member_expression())
syntax_error(String::format("Left-hand side of postfix increment operator must be identifier or member expression, got %s", lhs->class_name())); syntax_error(String::formatted("Left-hand side of postfix increment operator must be identifier or member expression, got {}", lhs->class_name()));
consume(); consume();
return create_ast_node<UpdateExpression>(UpdateOp::Decrement, move(lhs)); return create_ast_node<UpdateExpression>(UpdateOp::Decrement, move(lhs));
case TokenType::DoubleAmpersand: case TokenType::DoubleAmpersand:
@ -1790,7 +1790,7 @@ Token Parser::consume(TokenType expected_type)
void Parser::expected(const char* what) void Parser::expected(const char* what)
{ {
syntax_error(String::format("Unexpected token %s. Expected %s", m_parser_state.m_current_token.name(), what)); syntax_error(String::formatted("Unexpected token {}. Expected {}", m_parser_state.m_current_token.name(), what));
} }
void Parser::syntax_error(const String& message, size_t line, size_t column) void Parser::syntax_error(const String& message, size_t line, size_t column)

View file

@ -94,7 +94,7 @@ public:
{ {
if (line == 0 || column == 0) if (line == 0 || column == 0)
return message; return message;
return String::format("%s (line: %zu, column: %zu)", message.characters(), line, column); return String::formatted("{} (line: {}, column: {})", message, line, column);
} }
String source_location_hint(const StringView& source, const char spacer = ' ', const char indicator = '^') const String source_location_hint(const StringView& source, const char spacer = ' ', const char indicator = '^') const