Index: src/preparser.cc |
diff --git a/src/preparser.cc b/src/preparser.cc |
index df9e48ef769afa8b018d383c324440412819498e..8c8746d5e04a50315e1207773b208660f22ec9e7 100644 |
--- a/src/preparser.cc |
+++ b/src/preparser.cc |
@@ -61,6 +61,8 @@ PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) { |
} else if (scanner->current_token() == |
Token::FUTURE_STRICT_RESERVED_WORD) { |
return PreParserIdentifier::FutureStrictReserved(); |
+ } else if (scanner->current_token() == Token::LET) { |
+ return PreParserIdentifier::Let(); |
} else if (scanner->current_token() == Token::YIELD) { |
return PreParserIdentifier::Yield(); |
} |
@@ -167,9 +169,14 @@ PreParser::Statement PreParser::ParseSourceElement(bool* ok) { |
switch (peek()) { |
case Token::FUNCTION: |
return ParseFunctionDeclaration(ok); |
- case Token::LET: |
case Token::CONST: |
return ParseVariableStatement(kSourceElement, ok); |
+ case Token::LET: |
+ ASSERT(allow_harmony_scoping()); |
+ if (strict_mode() == STRICT) { |
+ return ParseVariableStatement(kSourceElement, ok); |
+ } |
+ // Fall through. |
default: |
return ParseStatement(ok); |
} |
@@ -237,11 +244,6 @@ PreParser::Statement PreParser::ParseStatement(bool* ok) { |
case Token::LBRACE: |
return ParseBlock(ok); |
- case Token::CONST: |
- case Token::LET: |
- case Token::VAR: |
- return ParseVariableStatement(kStatement, ok); |
- |
case Token::SEMICOLON: |
Next(); |
return Statement::Default(); |
@@ -297,6 +299,16 @@ PreParser::Statement PreParser::ParseStatement(bool* ok) { |
case Token::DEBUGGER: |
return ParseDebuggerStatement(ok); |
+ case Token::VAR: |
+ case Token::CONST: |
+ return ParseVariableStatement(kStatement, ok); |
+ |
+ case Token::LET: |
+ ASSERT(allow_harmony_scoping()); |
+ if (strict_mode() == STRICT) { |
+ return ParseVariableStatement(kStatement, ok); |
+ } |
+ // Fall through. |
default: |
return ParseExpressionOrLabelledStatement(ok); |
} |
@@ -415,23 +427,9 @@ PreParser::Statement PreParser::ParseVariableDeclarations( |
return Statement::Default(); |
} |
} |
- } else if (peek() == Token::LET) { |
- // ES6 Draft Rev4 section 12.2.1: |
- // |
- // LetDeclaration : let LetBindingList ; |
- // |
- // * It is a Syntax Error if the code that matches this production is not |
- // contained in extended code. |
- // |
- // TODO(rossberg): make 'let' a legal identifier in sloppy mode. |
- if (!allow_harmony_scoping() || strict_mode() == SLOPPY) { |
- ReportMessageAt(scanner()->peek_location(), "illegal_let"); |
- *ok = false; |
- return Statement::Default(); |
- } |
+ } else if (peek() == Token::LET && strict_mode() == STRICT) { |
Consume(Token::LET); |
- if (var_context != kSourceElement && |
- var_context != kForStatement) { |
+ if (var_context != kSourceElement && var_context != kForStatement) { |
ReportMessageAt(scanner()->peek_location(), "unprotected_let"); |
*ok = false; |
return Statement::Default(); |
@@ -669,7 +667,7 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) { |
Expect(Token::LPAREN, CHECK_OK); |
if (peek() != Token::SEMICOLON) { |
if (peek() == Token::VAR || peek() == Token::CONST || |
- peek() == Token::LET) { |
+ (peek() == Token::LET && strict_mode() == STRICT)) { |
bool is_let = peek() == Token::LET; |
int decl_count; |
VariableDeclarationProperties decl_props = kHasNoInitializers; |