case Token::LET:
case Token::CONST:
return ParseVariableStatement(kModuleElement, ok);
- case Token::MODULE:
- return ParseModuleDeclaration(ok);
case Token::IMPORT:
return ParseImportDeclaration(ok);
case Token::EXPORT:
return ParseExportDeclaration(ok);
- default:
- return ParseStatement(labels, ok);
+ default: {
+ 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;
+ }
}
}
// Create new block with one expected declaration.
Block* block = factory()->NewBlock(NULL, 1, true);
- Expect(Token::MODULE, CHECK_OK);
Handle<String> name = ParseIdentifier(CHECK_OK);
// top_scope_->AddDeclaration(
// factory()->NewModuleDeclaration(proxy, module, top_scope_));
return ParseNativeDeclaration(ok);
}
- // Parsed expression statement.
- ExpectSemicolon(CHECK_OK);
+ // Parsed expression statement, or the context-sensitive 'module' keyword.
+ // 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);
}
KEYWORD_GROUP('l') \
KEYWORD("let", harmony_scoping \
? Token::LET : Token::FUTURE_STRICT_RESERVED_WORD) \
- KEYWORD_GROUP('m') \
- KEYWORD("module", harmony_modules \
- ? Token::MODULE : Token::IDENTIFIER) \
KEYWORD_GROUP('n') \
KEYWORD("new", Token::NEW) \
KEYWORD("null", Token::NULL_LITERAL) \