mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 06:48:49 +00:00
LibJS: Parse object expressions
This commit is contained in:
parent
c64b5e73f5
commit
bc002f807a
Notes:
sideshowbarker
2024-07-19 08:12:30 +09:00
Author: https://github.com/0xtechnobabble
Commit: bc002f807a
Pull-request: https://github.com/SerenityOS/serenity/pull/1494
7 changed files with 48 additions and 4 deletions
|
@ -269,10 +269,27 @@ NonnullRefPtr<Expression> Parser::parse_unary_prefixed_expression()
|
|||
|
||||
NonnullRefPtr<ObjectExpression> Parser::parse_object_expression()
|
||||
{
|
||||
// FIXME: Parse actual object expression
|
||||
HashMap<String, NonnullRefPtr<Expression>> properties;
|
||||
consume(TokenType::CurlyOpen);
|
||||
|
||||
while (!match(TokenType::CurlyClose)) {
|
||||
auto identifier = create_ast_node<Identifier>(consume(TokenType::Identifier).value());
|
||||
|
||||
if (match(TokenType::Colon)) {
|
||||
consume(TokenType::Colon);
|
||||
properties.set(identifier->string(), parse_expression(0));
|
||||
} else {
|
||||
properties.set(identifier->string(), identifier);
|
||||
}
|
||||
|
||||
if (!match(TokenType::Comma))
|
||||
break;
|
||||
|
||||
consume(TokenType::Comma);
|
||||
}
|
||||
|
||||
consume(TokenType::CurlyClose);
|
||||
return create_ast_node<ObjectExpression>();
|
||||
return create_ast_node<ObjectExpression>(properties);
|
||||
}
|
||||
|
||||
NonnullRefPtr<ArrayExpression> Parser::parse_array_expression()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue