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

Unified Diff: src/parser.cc

Issue 378303003: Make `let` usable as an identifier in ES6 sloppy mode. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Comments Created 6 years, 5 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/messages.js ('k') | src/preparser.h » ('j') | no next file with comments »
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 b25a7b1af2054bb060ade921caa3911f5a20330f..65b22aa28ae06ff83606c3aa8520135c6fbfa540 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -1158,13 +1158,18 @@ Statement* Parser::ParseModuleElement(ZoneList<const AstRawString*>* labels,
switch (peek()) {
case Token::FUNCTION:
return ParseFunctionDeclaration(NULL, ok);
- case Token::LET:
- case Token::CONST:
- return ParseVariableStatement(kModuleElement, NULL, ok);
case Token::IMPORT:
return ParseImportDeclaration(ok);
case Token::EXPORT:
return ParseExportDeclaration(ok);
+ case Token::CONST:
+ return ParseVariableStatement(kModuleElement, NULL, ok);
+ case Token::LET:
+ ASSERT(allow_harmony_scoping());
+ if (strict_mode() == STRICT) {
+ return ParseVariableStatement(kModuleElement, NULL, ok);
+ }
+ // Fall through.
default: {
Statement* stmt = ParseStatement(labels, CHECK_OK);
// Handle 'module' as a context-sensitive keyword.
@@ -1463,6 +1468,8 @@ Statement* Parser::ParseExportDeclaration(bool* ok) {
//
// TODO(ES6): implement structuring ExportSpecifiers
+ ASSERT(strict_mode() == STRICT);
+
Expect(Token::EXPORT, CHECK_OK);
Statement* result = NULL;
@@ -1545,9 +1552,14 @@ Statement* Parser::ParseBlockElement(ZoneList<const AstRawString*>* labels,
switch (peek()) {
case Token::FUNCTION:
return ParseFunctionDeclaration(NULL, ok);
- case Token::LET:
case Token::CONST:
return ParseVariableStatement(kModuleElement, NULL, ok);
+ case Token::LET:
+ ASSERT(allow_harmony_scoping());
+ if (strict_mode() == STRICT) {
+ return ParseVariableStatement(kModuleElement, NULL, ok);
+ }
+ // Fall through.
default:
return ParseStatement(labels, ok);
}
@@ -1583,11 +1595,6 @@ Statement* Parser::ParseStatement(ZoneList<const AstRawString*>* labels,
case Token::LBRACE:
return ParseBlock(labels, ok);
- case Token::CONST: // fall through
- case Token::LET:
- case Token::VAR:
- return ParseVariableStatement(kStatement, NULL, ok);
-
case Token::SEMICOLON:
Next();
return factory()->NewEmptyStatement(RelocInfo::kNoPosition);
@@ -1659,6 +1666,16 @@ Statement* Parser::ParseStatement(ZoneList<const AstRawString*>* labels,
case Token::DEBUGGER:
return ParseDebuggerStatement(ok);
+ case Token::VAR:
+ case Token::CONST:
+ return ParseVariableStatement(kStatement, NULL, ok);
+
+ case Token::LET:
+ ASSERT(allow_harmony_scoping());
+ if (strict_mode() == STRICT) {
+ return ParseVariableStatement(kStatement, NULL, ok);
+ }
+ // Fall through.
default:
return ParseExpressionOrLabelledStatement(labels, ok);
}
@@ -2062,20 +2079,7 @@ Block* Parser::ParseVariableDeclarations(
}
is_const = true;
needs_init = true;
- } 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) {
- ReportMessage("illegal_let");
- *ok = false;
- return NULL;
- }
+ } else if (peek() == Token::LET && strict_mode() == STRICT) {
marja 2014/07/10 14:05:28 Here you probably also want to ASSERT(allow_harmon
Consume(Token::LET);
if (var_context == kStatement) {
// Let declarations are only allowed in source element positions.
@@ -3114,7 +3118,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
} else {
init = variable_statement;
}
- } else if (peek() == Token::LET) {
+ } else if (peek() == Token::LET && strict_mode() == STRICT) {
marja 2014/07/10 14:05:28 Ditto
const AstRawString* name = NULL;
VariableDeclarationProperties decl_props = kHasNoInitializers;
Block* variable_statement =
@@ -3500,8 +3504,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
fvar_init_op = Token::INIT_CONST;
}
VariableMode fvar_mode =
- allow_harmony_scoping() && strict_mode() == STRICT ? CONST
- : CONST_LEGACY;
+ allow_harmony_scoping() && strict_mode() == STRICT
+ ? CONST : CONST_LEGACY;
ASSERT(function_name != NULL);
fvar = new(zone()) Variable(scope_,
function_name, fvar_mode, true /* is valid LHS */,
« no previous file with comments | « src/messages.js ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698