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

Unified Diff: src/preparser.h

Issue 1167393005: [destructuring] Parse binding patterns in formal parameters. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: CR feedback + rebase Created 5 years, 6 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/parser.cc ('k') | src/preparser.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 fe31564daf71242c3197a41d30dc758d2622febf..41ebf97280fbcae62ddc36e86149a1a25aa1f9c8 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -555,7 +555,7 @@ class ParserBase : public Traits {
ExpressionT expr, bool* ok) {
if (classifier->is_valid_binding_pattern()) {
// A simple arrow formal parameter: IDENTIFIER => BODY.
- if (!this->IsIdentifier(expr)) {
+ if (!allow_harmony_destructuring() && !this->IsIdentifier(expr)) {
Traits::ReportMessageAt(scanner()->location(),
MessageTemplate::kUnexpectedToken,
Token::String(scanner()->current_token()));
@@ -1555,7 +1555,7 @@ class PreParserTraits {
return !tag.IsNoTemplateTag();
}
- void DeclareFormalParameter(Scope* scope, PreParserIdentifier param,
+ void DeclareFormalParameter(Scope* scope, PreParserExpression pattern,
ExpressionClassifier* classifier, bool is_rest) {}
void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {}
@@ -3487,10 +3487,21 @@ void ParserBase<Traits>::ParseFormalParameter(Scope* scope, bool is_rest,
bool* ok) {
// FormalParameter[Yield,GeneratorParameter] :
// BindingElement[?Yield, ?GeneratorParameter]
- IdentifierT name = ParseAndClassifyIdentifier(classifier, ok);
+
+ Token::Value next = peek();
+ ExpressionT pattern = ParsePrimaryExpression(classifier, ok);
+ if (!*ok) return;
+
+ ValidateBindingPattern(classifier, ok);
if (!*ok) return;
- Traits::DeclareFormalParameter(scope, name, classifier, is_rest);
+ if (!allow_harmony_destructuring() && !Traits::IsIdentifier(pattern)) {
+ ReportUnexpectedToken(next);
+ *ok = false;
+ return;
+ }
+
+ Traits::DeclareFormalParameter(scope, pattern, classifier, is_rest);
}
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698