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

Unified Diff: src/parser.cc

Issue 1416753009: [parser] early error when declaration Pattern missing Initializer (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add a bunch of message tests + refactor a bit Created 5 years, 1 month 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/messages.h ('k') | src/preparser.h » ('j') | src/preparser.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index b54172f72c21cc6ccf320ed04877227804a5d134..e8bb657ffd1cab3fa4c12c52ece503830f91d6af 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -2531,6 +2531,8 @@ void Parser::ParseVariableDeclarations(VariableDeclarationContext var_context,
if (!first_declaration) Consume(Token::COMMA);
Expression* pattern;
+ bool is_pattern = false;
rossberg 2015/11/04 10:52:35 Nit: declare this after the block and initialise d
+ int decl_pos = peek_position();
{
ExpressionClassifier pattern_classifier;
Token::Value next = peek();
@@ -2547,6 +2549,7 @@ void Parser::ParseVariableDeclarations(VariableDeclarationContext var_context,
*ok = false;
return;
}
+ is_pattern = pattern->IsObjectLiteral() || pattern->IsArrayLiteral();
}
Scanner::Location variable_loc = scanner()->location();
@@ -2569,10 +2572,18 @@ void Parser::ParseVariableDeclarations(VariableDeclarationContext var_context,
Expression* value = NULL;
// Harmony consts have non-optional initializers.
int initializer_position = RelocInfo::kNoPosition;
- if (peek() == Token::ASSIGN || (parsing_result->descriptor.mode == CONST &&
- !is_for_iteration_variable)) {
- Expect(Token::ASSIGN, ok);
- if (!*ok) return;
+ if (peek() == Token::ASSIGN ||
+ ((parsing_result->descriptor.mode == CONST || is_pattern) &&
rossberg 2015/11/04 10:52:35 Why not test these in the else branch and move the
caitp (gmail) 2015/11/04 15:07:28 I think I've done what you're asking for here ---
+ !is_for_iteration_variable)) {
+ if (peek() != Token::ASSIGN) {
adamk 2015/11/04 00:37:54 You can also consume here to avoid mentioning ASSI
caitp (gmail) 2015/11/04 00:50:02 Yeah, it messes up the positioning a bit if i do t
adamk 2015/11/04 00:55:10 Ah, right, feel free to leave as-is.
+ ParserTraits::ReportMessageAt(
+ Scanner::Location(decl_pos, scanner()->location().end_pos),
adamk 2015/11/04 00:37:54 I'm not sure this location makes any more sense th
caitp (gmail) 2015/11/04 00:50:02 If the devtools actually showed the positions, I'd
adamk 2015/11/04 00:55:10 I too have been wondering why devtools doesn't sho
+ MessageTemplate::kDeclarationMissingInitializer,
+ is_pattern ? "destructuring" : "const");
+ *ok = false;
+ return;
+ }
+ Consume(Token::ASSIGN);
ExpressionClassifier classifier;
value = ParseAssignmentExpression(var_context != kForStatement,
&classifier, ok);
« no previous file with comments | « src/messages.h ('k') | src/preparser.h » ('j') | src/preparser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698