diff options
author | mattco98 <matthewcolsson@gmail.com> | 2020-04-27 21:52:47 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-28 20:37:21 +0200 |
commit | 104969a9f5c4eaacbdc89b548729a8edeada5fff (patch) | |
tree | baf98659a032a9506a9713c4b39ce7c3b28882e9 /Libraries/LibJS/Parser.cpp | |
parent | 3cc31ff3f3d96ddbac662669c50edb1be01abe3a (diff) | |
download | serenity-104969a9f5c4eaacbdc89b548729a8edeada5fff.zip |
LibJS: Add spreading in object literals
Supports spreading strings, arrays, and other objects within object
literals.
Diffstat (limited to 'Libraries/LibJS/Parser.cpp')
-rw-r--r-- | Libraries/LibJS/Parser.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp index 63e0a5bd95..2288a31d92 100644 --- a/Libraries/LibJS/Parser.cpp +++ b/Libraries/LibJS/Parser.cpp @@ -446,6 +446,8 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression() RefPtr<Expression> property_key; RefPtr<Expression> property_value; auto need_colon = true; + auto is_spread = false; + if (match_identifier_name()) { auto identifier = consume().value(); property_key = create_ast_node<StringLiteral>(identifier); @@ -459,6 +461,12 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression() consume(TokenType::BracketOpen); property_key = parse_expression(0); consume(TokenType::BracketClose); + } else if (match(TokenType::TripleDot)) { + consume(TokenType::TripleDot); + property_key = create_ast_node<SpreadExpression>(parse_expression(0)); + property_value = property_key; + need_colon = false; + is_spread = true; } else { m_parser_state.m_has_errors = true; auto& current_token = m_parser_state.m_current_token; @@ -476,6 +484,8 @@ NonnullRefPtr<ObjectExpression> Parser::parse_object_expression() } auto property = create_ast_node<ObjectProperty>(*property_key, *property_value); properties.append(property); + if (is_spread) + property->set_is_spread(); if (!match(TokenType::Comma)) break; |