Index: src/preparser.cc |
diff --git a/src/preparser.cc b/src/preparser.cc |
index 4d621c2dd9004c0a2b3434a8be2e561b42cfc1ee..6b9756dff0be8752e4db9a92481b0aaf70fa87b9 100644 |
--- a/src/preparser.cc |
+++ b/src/preparser.cc |
@@ -162,16 +162,22 @@ PreParserExpression PreParserTraits::ParseClassLiteral( |
PreParser::Statement PreParser::ParseSourceElement(bool* ok) { |
- // (Ecma 262 5th Edition, clause 14): |
- // SourceElement: |
- // Statement |
- // FunctionDeclaration |
+ // ECMA 262 6th Edition |
+ // StatementListItem[Yield, Return] : |
+ // Statement[?Yield, ?Return] |
+ // Declaration[?Yield] |
// |
- // In harmony mode we allow additionally the following productions |
- // SourceElement: |
- // LetDeclaration |
- // ConstDeclaration |
- // GeneratorDeclaration |
+ // Declaration[Yield] : |
+ // HoistableDeclaration[?Yield] |
+ // ClassDeclaration[?Yield] |
+ // LexicalDeclaration[In, ?Yield] |
+ // |
+ // HoistableDeclaration[Yield, Default] : |
+ // FunctionDeclaration[?Yield, ?Default] |
+ // GeneratorDeclaration[?Yield, ?Default] |
+ // |
+ // LexicalDeclaration[In, Yield] : |
+ // LetOrConst BindingList[?In, ?Yield] ; |
switch (peek()) { |
case Token::FUNCTION: |
@@ -305,22 +311,21 @@ PreParser::Statement PreParser::ParseStatement(bool* ok) { |
} |
} |
- case Token::CLASS: |
- return ParseClassDeclaration(CHECK_OK); |
- |
case Token::DEBUGGER: |
return ParseDebuggerStatement(ok); |
case Token::VAR: |
- case Token::CONST: |
return ParseVariableStatement(kStatement, ok); |
- case Token::LET: |
- DCHECK(allow_harmony_scoping()); |
- if (strict_mode() == STRICT) { |
+ case Token::CONST: |
+ // In ES6 CONST is not allowed as a Statement , only as a |
+ // LexicalDeclaration, however we continue to allow it in sloppy mode for |
+ // backwards compatibility. |
+ if (strict_mode() == SLOPPY) { |
return ParseVariableStatement(kStatement, ok); |
} |
- // Fall through. |
+ |
+ // Fall through. |
default: |
return ParseExpressionOrLabelledStatement(ok); |
} |
@@ -497,6 +502,22 @@ PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { |
// Expression ';' |
// Identifier ':' Statement |
+ switch (peek()) { |
+ case Token::FUNCTION: |
+ case Token::LBRACE: |
+ UNREACHABLE(); // Always handled by the callers. |
+ case Token::CLASS: |
+ ReportUnexpectedToken(Next()); |
+ *ok = false; |
+ return Statement::Default(); |
+ |
+ // TODO(arv): Handle `let [` |
+ // https://code.google.com/p/v8/issues/detail?id=3847 |
+ |
+ default: |
+ break; |
+ } |
+ |
bool starts_with_identifier = peek_any_identifier(); |
Expression expr = ParseExpression(true, CHECK_OK); |
// Even if the expression starts with an identifier, it is not necessarily an |