summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries/LibJS/Parser.cpp')
-rw-r--r--Libraries/LibJS/Parser.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp
index bd02564ad8..badcd97268 100644
--- a/Libraries/LibJS/Parser.cpp
+++ b/Libraries/LibJS/Parser.cpp
@@ -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()