LibJS: Require colon in object expression for non-identifier keys
{foo} is valid - {"foo"} or {1} is not.
This commit is contained in:
parent
402ba20c36
commit
bebd5c097c
Notes:
sideshowbarker
2024-07-19 07:21:02 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/bebd5c097c9 Pull-request: https://github.com/SerenityOS/serenity/pull/1932 Reviewed-by: https://github.com/awesomekling
1 changed files with 3 additions and 1 deletions
|
@ -440,8 +440,10 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression()
|
|||
|
||||
while (!done() && !match(TokenType::CurlyClose)) {
|
||||
FlyString property_name;
|
||||
auto need_colon = true;
|
||||
if (match_identifier_name()) {
|
||||
property_name = consume().value();
|
||||
need_colon = false;
|
||||
} else if (match(TokenType::StringLiteral)) {
|
||||
property_name = consume(TokenType::StringLiteral).string_value();
|
||||
} else if (match(TokenType::NumericLiteral)) {
|
||||
|
@ -457,7 +459,7 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression()
|
|||
continue;
|
||||
}
|
||||
|
||||
if (match(TokenType::Colon)) {
|
||||
if (need_colon || match(TokenType::Colon)) {
|
||||
consume(TokenType::Colon);
|
||||
properties.set(property_name, parse_expression(0));
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue