Index: src/parsing/parser-base.h |
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h |
index 9ce9c32309328c7cc890f4877ed169897099685b..b4808dddc9dad0dbfcb108e51e2ca98a949270de 100644 |
--- a/src/parsing/parser-base.h |
+++ b/src/parsing/parser-base.h |
@@ -217,7 +217,8 @@ class ParserBase { |
allow_harmony_async_await_(false), |
allow_harmony_restrictive_generators_(false), |
allow_harmony_trailing_commas_(false), |
- allow_harmony_class_fields_(false) {} |
+ allow_harmony_class_fields_(false), |
+ allow_harmony_object_spread_(false) {} |
#define ALLOW_ACCESSORS(name) \ |
bool allow_##name() const { return allow_##name##_; } \ |
@@ -231,6 +232,7 @@ class ParserBase { |
ALLOW_ACCESSORS(harmony_restrictive_generators); |
ALLOW_ACCESSORS(harmony_trailing_commas); |
ALLOW_ACCESSORS(harmony_class_fields); |
+ ALLOW_ACCESSORS(harmony_object_spread); |
#undef ALLOW_ACCESSORS |
@@ -1149,6 +1151,7 @@ class ParserBase { |
kShorthandProperty, |
kMethodProperty, |
kClassField, |
+ kSpreadProperty, |
kNotSet |
}; |
@@ -1455,6 +1458,7 @@ class ParserBase { |
bool allow_harmony_restrictive_generators_; |
bool allow_harmony_trailing_commas_; |
bool allow_harmony_class_fields_; |
+ bool allow_harmony_object_spread_; |
friend class DiscardableZoneScope; |
}; |
@@ -2108,6 +2112,22 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePropertyName( |
break; |
} |
+ case Token::ELLIPSIS: { |
+ if (allow_harmony_object_spread()) { |
+ // TODO(gsathya): Implement destructuring/rest |
+ BindingPatternUnexpectedToken(); |
adamk
2016/12/29 00:48:45
I think you'll need to disallow this in assignment
gsathya
2016/12/29 06:40:56
Done.
adamk
2016/12/29 18:32:45
You can get both at once with
classifier()->Recor
gsathya
2017/01/05 22:18:35
Done.
|
+ |
+ *name = impl()->EmptyIdentifier(); |
+ Consume(Token::ELLIPSIS); |
+ ExpressionClassifier spread_classifier(this); |
+ expression = ParseAssignmentExpression(false, CHECK_OK); |
adamk
2016/12/29 00:48:45
Don't you want to accept "in"? Please add a test,
gsathya
2016/12/29 06:40:56
Done.
|
+ impl()->RewriteNonPattern(CHECK_OK); |
+ impl()->AccumulateFormalParameterContainmentErrors(); |
+ *kind = PropertyKind::kSpreadProperty; |
+ return expression; |
+ } |
+ } |
+ |
default: |
*name = ParseIdentifierName(CHECK_OK); |
break; |
@@ -2268,6 +2288,8 @@ ParserBase<Impl>::ParseClassPropertyDefinition( |
*property_kind, *is_static, |
*is_computed_name); |
} |
+ case PropertyKind::kSpreadProperty: |
+ UNREACHABLE(); |
} |
UNREACHABLE(); |
return impl()->EmptyClassLiteralProperty(); |
@@ -2329,6 +2351,20 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ObjectLiteralChecker* checker, |
is_computed_name, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
switch (kind) { |
+ case PropertyKind::kSpreadProperty: { |
+ if (allow_harmony_object_spread()) { |
adamk
2016/12/29 00:48:45
This can be a DCHECK, since ParsePropertyName shou
gsathya
2016/12/29 06:40:56
Done.
|
+ DCHECK(!is_get && !is_set && !is_generator && !is_async); |
adamk
2016/12/29 00:48:45
you should add !*is_computed_name to this list.
gsathya
2016/12/29 06:40:56
Done.
|
+ DCHECK(name_token == Token::ELLIPSIS); |
+ |
+ *is_computed_name = true; |
+ *ok = true; |
adamk
2016/12/29 00:48:45
No need to set *ok to true, that's how it starts.
gsathya
2016/12/29 06:40:56
Done.
|
+ |
+ return factory()->NewObjectLiteralProperty( |
+ impl()->GetLiteralTheHole(kNoSourcePosition), name_expression, |
+ ObjectLiteralProperty::SPREAD, true); |
+ } |
+ } |
+ |
case PropertyKind::kValueProperty: { |
DCHECK(!is_get && !is_set && !is_generator && !is_async); |