Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(669)

Unified Diff: src/preparser.h

Issue 1146683002: [destructuring] Implement initializers in patterns. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased onto ToT Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pattern-rewriter.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 379d41879c3b9f364a6da460964ccd17a9b4f9ce..b08888834eb9ba4a42c557f8cd2d3dfa849c9520 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -691,8 +691,10 @@ class ParserBase : public Traits {
ArrowFormalParametersProduction = 1 << 4,
StandardProductions = (ExpressionProduction | BindingPatternProduction |
AssignmentPatternProduction),
+ PatternProductions =
+ BindingPatternProduction | AssignmentPatternProduction,
AllProductions = (StandardProductions | FormalParametersProduction |
- ArrowFormalParametersProduction)
+ ArrowFormalParametersProduction),
};
void Accumulate(const ExpressionClassifier& inner,
@@ -730,6 +732,18 @@ class ParserBase : public Traits {
}
}
+ void AccumulateReclassifyingAsPattern(const ExpressionClassifier& inner) {
+ Accumulate(inner, AllProductions & ~PatternProductions);
+ if (!inner.is_valid_expression()) {
+ if (is_valid_binding_pattern()) {
+ binding_pattern_error_ = inner.expression_error();
+ }
+ if (is_valid_assignment_pattern()) {
+ assignment_pattern_error_ = inner.expression_error();
+ }
+ }
+ }
+
private:
Error expression_error_;
Error binding_pattern_error_;
@@ -803,6 +817,12 @@ class ParserBase : public Traits {
}
}
+ void ExpressionUnexpectedToken(ExpressionClassifier* classifier) {
+ classifier->RecordExpressionError(scanner()->peek_location(),
+ MessageTemplate::kUnexpectedToken,
+ Token::String(peek()));
+ }
+
void BindingPatternUnexpectedToken(ExpressionClassifier* classifier) {
classifier->RecordBindingPatternError(scanner()->peek_location(),
MessageTemplate::kUnexpectedToken,
@@ -2677,8 +2697,21 @@ ParserBase<Traits>::ParsePropertyDefinition(
this->is_generator())) {
DCHECK(!*is_computed_name);
DCHECK(!is_static);
- value = this->ExpressionFromIdentifier(name, next_beg_pos, next_end_pos,
- scope_, factory());
+
+ ExpressionT lhs = this->ExpressionFromIdentifier(
+ name, next_beg_pos, next_end_pos, scope_, factory());
+ if (peek() == Token::ASSIGN) {
+ this->ExpressionUnexpectedToken(classifier);
+ Consume(Token::ASSIGN);
+ ExpressionClassifier rhs_classifier;
+ ExpressionT rhs = this->ParseAssignmentExpression(
+ true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
+ classifier->AccumulateReclassifyingAsPattern(rhs_classifier);
+ value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs,
+ RelocInfo::kNoPosition);
+ } else {
+ value = lhs;
+ }
return factory()->NewObjectLiteralProperty(
name_expression, value, ObjectLiteralProperty::COMPUTED, false, false);
@@ -2900,9 +2933,17 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
expression = this->MarkExpressionAsAssigned(expression);
Token::Value op = Next(); // Get assignment operator.
+ if (op != Token::ASSIGN) {
+ classifier->RecordBindingPatternError(scanner()->location(),
+ MessageTemplate::kUnexpectedToken,
+ Token::String(op));
+ }
int pos = position();
+
+ ExpressionClassifier rhs_classifier;
ExpressionT right =
- this->ParseAssignmentExpression(accept_IN, classifier, CHECK_OK);
+ this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK);
+ classifier->AccumulateReclassifyingAsPattern(rhs_classifier);
// TODO(1231235): We try to estimate the set of properties set by
// constructors. We define a new property whenever there is an
« no previous file with comments | « src/pattern-rewriter.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698