Index: src/pattern-rewriter.cc |
diff --git a/src/pattern-rewriter.cc b/src/pattern-rewriter.cc |
index 9f24a395a25c4a24d1a17a9e7f75eb0b97bef1ee..a97c009708cdd1ffbb793654a1b5838339cf3e8c 100644 |
--- a/src/pattern-rewriter.cc |
+++ b/src/pattern-rewriter.cc |
@@ -208,17 +208,22 @@ void Parser::PatternRewriter::VisitVariableProxy(VariableProxy* pattern) { |
} |
-void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern) { |
- auto temp = TemporaryDeclarationScope()->NewTemporary( |
- ast_value_factory()->empty_string()); |
+Variable* Parser::PatternRewriter::CreateTempVar(Expression* value) { |
+ auto temp_scope = descriptor_->parser->scope_->DeclarationScope(); |
+ auto temp = temp_scope->NewTemporary(ast_value_factory()->empty_string()); |
auto assignment = |
factory()->NewAssignment(Token::ASSIGN, factory()->NewVariableProxy(temp), |
- current_value_, RelocInfo::kNoPosition); |
+ value, RelocInfo::kNoPosition); |
block_->AddStatement( |
factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), |
zone()); |
+ return temp; |
+} |
+ |
+void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern) { |
+ auto temp = CreateTempVar(current_value_); |
if (pattern->properties()->length() == 0) { |
block_->AddStatement(descriptor_->parser->BuildAssertIsCoercible(temp), |
zone()); |
@@ -240,7 +245,20 @@ void Parser::PatternRewriter::VisitArrayLiteral(ArrayLiteral* node) { |
void Parser::PatternRewriter::VisitAssignment(Assignment* node) { |
- // TODO(dslomov): implement. |
+ // let {<pattern> = <init>} = <value> |
+ // becomes |
+ // temp = <value>; |
+ // <pattern> = temp === undefined ? <init> : temp; |
+ DCHECK(node->op() == Token::ASSIGN); |
+ auto temp = CreateTempVar(current_value_); |
+ Expression* is_undefined = factory()->NewCompareOperation( |
+ Token::EQ_STRICT, factory()->NewVariableProxy(temp), |
+ factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), |
+ RelocInfo::kNoPosition); |
+ Expression* value = factory()->NewConditional( |
+ is_undefined, node->value(), factory()->NewVariableProxy(temp), |
+ RelocInfo::kNoPosition); |
+ RecurseIntoSubpattern(node->target(), value); |
} |