Index: src/pattern-rewriter.cc |
diff --git a/src/pattern-rewriter.cc b/src/pattern-rewriter.cc |
index 52ff8f60f10bca57bc487195f8107e0ddea3ad8e..8767b1f8d7424bf5e31279320c014aecc609f269 100644 |
--- a/src/pattern-rewriter.cc |
+++ b/src/pattern-rewriter.cc |
@@ -246,7 +246,14 @@ void Parser::PatternRewriter::VisitArrayLiteral(ArrayLiteral* node) { |
factory()->NewBooleanLiteral(false, RelocInfo::kNoPosition)); |
auto result = CreateTempVar(); |
auto v = CreateTempVar(); |
+ |
+ Spread* spread = nullptr; |
for (Expression* value : *node->values()) { |
+ if (value->IsSpread()) { |
+ spread = value->AsSpread(); |
+ break; |
+ } |
+ |
// if (!done) { |
// result = IteratorNext(iterator); |
// v = (done = result.done) ? undefined : result.value; |
@@ -296,6 +303,39 @@ void Parser::PatternRewriter::VisitArrayLiteral(ArrayLiteral* node) { |
RecurseIntoSubpattern(value, factory()->NewVariableProxy(v)); |
} |
} |
+ |
+ if (spread != nullptr) { |
+ // array = []; |
+ // if (!done) $concatIterableToArray(array, iterator); |
+ auto empty_exprs = new (zone()) ZoneList<Expression*>(0, zone()); |
+ auto array = CreateTempVar(factory()->NewArrayLiteral( |
+ empty_exprs, |
+ // Reuse pattern's literal index - it is unused since there is no |
arv (Not doing code reviews)
2015/05/20 14:40:50
nice.
|
+ // actual literal allocated. |
+ node->literal_index(), is_strong(descriptor_->parser->language_mode()), |
+ RelocInfo::kNoPosition)); |
+ |
+ auto arguments = new (zone()) ZoneList<Expression*>(2, zone()); |
+ arguments->Add(factory()->NewVariableProxy(array), zone()); |
+ arguments->Add(factory()->NewVariableProxy(iterator), zone()); |
+ auto spread_into_array_call = factory()->NewCallRuntime( |
+ ast_value_factory()->concat_iterable_to_array_string(), nullptr, |
+ arguments, RelocInfo::kNoPosition); |
+ |
+ auto if_statement = factory()->NewIfStatement( |
+ factory()->NewUnaryOperation(Token::NOT, |
+ factory()->NewVariableProxy(done), |
+ RelocInfo::kNoPosition), |
+ factory()->NewExpressionStatement(spread_into_array_call, |
+ RelocInfo::kNoPosition), |
+ factory()->NewEmptyStatement(RelocInfo::kNoPosition), |
+ RelocInfo::kNoPosition); |
+ block_->AddStatement(if_statement, zone()); |
+ |
+ |
+ RecurseIntoSubpattern(spread->expression(), |
+ factory()->NewVariableProxy(array)); |
+ } |
} |