diff --git a/src/parser.cc b/src/parser.cc index f4828a0d5c..aa6ee8ccb6 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -1422,16 +1422,19 @@ Statement* Parser::ParseImportDeclaration(bool* ok) { } // Parse ImportedDefaultBinding if present. - const AstRawString* imported_default_binding = NULL; + ImportDeclaration* import_default_declaration = NULL; if (tok != Token::MUL && tok != Token::LBRACE) { - imported_default_binding = + const AstRawString* local_name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); - // TODO(ES6): Add an appropriate declaration. + VariableProxy* proxy = NewUnresolved(local_name, IMPORT); + import_default_declaration = factory()->NewImportDeclaration( + proxy, ast_value_factory()->default_string(), NULL, scope_, pos); + Declare(import_default_declaration, true, CHECK_OK); } const AstRawString* module_instance_binding = NULL; ZoneList* named_declarations = NULL; - if (imported_default_binding == NULL || Check(Token::COMMA)) { + if (import_default_declaration == NULL || Check(Token::COMMA)) { switch (peek()) { case Token::MUL: { Consume(Token::MUL); @@ -1461,8 +1464,8 @@ Statement* Parser::ParseImportDeclaration(bool* ok) { // TODO(ES6): Set the module specifier for the module namespace binding. } - if (imported_default_binding != NULL) { - // TODO(ES6): Set the module specifier for the default binding. + if (import_default_declaration != NULL) { + import_default_declaration->set_module_specifier(module_specifier); } if (named_declarations != NULL) { diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc index fcc096af85..6bbd4e9613 100644 --- a/test/cctest/test-parsing.cc +++ b/test/cctest/test-parsing.cc @@ -5219,7 +5219,10 @@ TEST(ModuleParsingInternals) { 128 * 1024); static const char kSource[] = - "let x = 5; export { x as y }; import { q as z } from 'm.js';"; + "let x = 5;" + "export { x as y };" + "import { q as z } from 'm.js';" + "import n from 'n.js'"; i::Handle source = factory->NewStringFromAsciiChecked(kSource); i::Handle script = factory->NewScript(source); i::CompilationInfoWithZone info(script); @@ -5242,13 +5245,17 @@ TEST(ModuleParsingInternals) { CHECK_NOT_NULL(local_name); CHECK(local_name->IsOneByteEqualTo("x")); i::ZoneList* declarations = func->scope()->declarations(); - CHECK_EQ(2, declarations->length()); + CHECK_EQ(3, declarations->length()); CHECK(declarations->at(0)->proxy()->raw_name()->IsOneByteEqualTo("x")); i::ImportDeclaration* import_decl = declarations->at(1)->AsImportDeclaration(); CHECK(import_decl->import_name()->IsOneByteEqualTo("q")); CHECK(import_decl->proxy()->raw_name()->IsOneByteEqualTo("z")); CHECK(import_decl->module_specifier()->IsOneByteEqualTo("m.js")); + import_decl = declarations->at(2)->AsImportDeclaration(); + CHECK(import_decl->import_name()->IsOneByteEqualTo("default")); + CHECK(import_decl->proxy()->raw_name()->IsOneByteEqualTo("n")); + CHECK(import_decl->module_specifier()->IsOneByteEqualTo("n.js")); }