Commit becd8dd1 authored by rossberg@chromium.org's avatar rossberg@chromium.org

Make 'module' a context-sensitive keyword.

Baseline: http://codereview.chromium.org/9401008/

R=lrn@chromium.org,mstarzinger@chromium.org
BUG=v8:1957
TEST=mjsunit/harmony/module-parsing

Review URL: https://chromiumcodereview.appspot.com/9422001

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10832 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 2fe4af71
...@@ -177,6 +177,7 @@ namespace internal { ...@@ -177,6 +177,7 @@ namespace internal {
V(eval_symbol, "eval") \ V(eval_symbol, "eval") \
V(function_symbol, "function") \ V(function_symbol, "function") \
V(length_symbol, "length") \ V(length_symbol, "length") \
V(module_symbol, "module") \
V(name_symbol, "name") \ V(name_symbol, "name") \
V(native_symbol, "native") \ V(native_symbol, "native") \
V(null_symbol, "null") \ V(null_symbol, "null") \
......
...@@ -1188,14 +1188,28 @@ Statement* Parser::ParseModuleElement(ZoneStringList* labels, ...@@ -1188,14 +1188,28 @@ Statement* Parser::ParseModuleElement(ZoneStringList* labels,
case Token::LET: case Token::LET:
case Token::CONST: case Token::CONST:
return ParseVariableStatement(kModuleElement, ok); return ParseVariableStatement(kModuleElement, ok);
case Token::MODULE:
return ParseModuleDeclaration(ok);
case Token::IMPORT: case Token::IMPORT:
return ParseImportDeclaration(ok); return ParseImportDeclaration(ok);
case Token::EXPORT: case Token::EXPORT:
return ParseExportDeclaration(ok); return ParseExportDeclaration(ok);
default: default: {
return ParseStatement(labels, ok); Statement* stmt = ParseStatement(labels, CHECK_OK);
// Handle 'module' as a context-sensitive keyword.
if (FLAG_harmony_modules &&
peek() == Token::IDENTIFIER &&
!scanner().HasAnyLineTerminatorBeforeNext() &&
stmt != NULL) {
ExpressionStatement* estmt = stmt->AsExpressionStatement();
if (estmt != NULL &&
estmt->expression()->AsVariableProxy() != NULL &&
estmt->expression()->AsVariableProxy()->name()->Equals(
isolate()->heap()->module_symbol()) &&
!scanner().literal_contains_escapes()) {
return ParseModuleDeclaration(ok);
}
}
return stmt;
}
} }
} }
...@@ -1206,7 +1220,6 @@ Block* Parser::ParseModuleDeclaration(bool* ok) { ...@@ -1206,7 +1220,6 @@ Block* Parser::ParseModuleDeclaration(bool* ok) {
// Create new block with one expected declaration. // Create new block with one expected declaration.
Block* block = factory()->NewBlock(NULL, 1, true); Block* block = factory()->NewBlock(NULL, 1, true);
Expect(Token::MODULE, CHECK_OK);
Handle<String> name = ParseIdentifier(CHECK_OK); Handle<String> name = ParseIdentifier(CHECK_OK);
// top_scope_->AddDeclaration( // top_scope_->AddDeclaration(
// factory()->NewModuleDeclaration(proxy, module, top_scope_)); // factory()->NewModuleDeclaration(proxy, module, top_scope_));
...@@ -2172,8 +2185,17 @@ Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels, ...@@ -2172,8 +2185,17 @@ Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels,
return ParseNativeDeclaration(ok); return ParseNativeDeclaration(ok);
} }
// Parsed expression statement. // Parsed expression statement, or the context-sensitive 'module' keyword.
ExpectSemicolon(CHECK_OK); // Only expect semicolon in the former case.
if (!FLAG_harmony_modules ||
peek() != Token::IDENTIFIER ||
scanner().HasAnyLineTerminatorBeforeNext() ||
expr->AsVariableProxy() == NULL ||
!expr->AsVariableProxy()->name()->Equals(
isolate()->heap()->module_symbol()) ||
scanner().literal_contains_escapes()) {
ExpectSemicolon(CHECK_OK);
}
return factory()->NewExpressionStatement(expr); return factory()->NewExpressionStatement(expr);
} }
......
...@@ -850,9 +850,6 @@ uc32 Scanner::ScanIdentifierUnicodeEscape() { ...@@ -850,9 +850,6 @@ uc32 Scanner::ScanIdentifierUnicodeEscape() {
KEYWORD_GROUP('l') \ KEYWORD_GROUP('l') \
KEYWORD("let", harmony_scoping \ KEYWORD("let", harmony_scoping \
? Token::LET : Token::FUTURE_STRICT_RESERVED_WORD) \ ? Token::LET : Token::FUTURE_STRICT_RESERVED_WORD) \
KEYWORD_GROUP('m') \
KEYWORD("module", harmony_modules \
? Token::MODULE : Token::IDENTIFIER) \
KEYWORD_GROUP('n') \ KEYWORD_GROUP('n') \
KEYWORD("new", Token::NEW) \ KEYWORD("new", Token::NEW) \
KEYWORD("null", Token::NULL_LITERAL) \ KEYWORD("null", Token::NULL_LITERAL) \
......
...@@ -173,7 +173,6 @@ namespace internal { ...@@ -173,7 +173,6 @@ namespace internal {
K(EXPORT, "export", 0) \ K(EXPORT, "export", 0) \
K(IMPORT, "import", 0) \ K(IMPORT, "import", 0) \
K(LET, "let", 0) \ K(LET, "let", 0) \
K(MODULE, "module", 0) \
\ \
/* Illegal token - not able to scan. */ \ /* Illegal token - not able to scan. */ \
T(ILLEGAL, "ILLEGAL", 0) \ T(ILLEGAL, "ILLEGAL", 0) \
......
...@@ -63,18 +63,28 @@ module E3 = E1.F ...@@ -63,18 +63,28 @@ module E3 = E1.F
// Check that ASI does not interfere. // Check that ASI does not interfere.
module module X
X
{ {
let x let x
} }
module module Y
Y
= =
X X
module module Z
Z
at at
"file://local" "file://local"
// Check that 'module' still works as an identifier.
var module
module = {}
module["a"] = 6
function module() {}
function f(module) { return module }
try {} catch (module) {}
module
v = 20
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment