Commit 38d7a796 authored by adamk's avatar adamk Committed by Commit bot

Create ImportDeclarations for default imports.

BUG=v8:1569
LOG=n

Review URL: https://codereview.chromium.org/958213006

Cr-Commit-Position: refs/heads/master@{#26921}
parent a7840a2b
......@@ -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<ImportDeclaration*>* 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) {
......
......@@ -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<i::String> source = factory->NewStringFromAsciiChecked(kSource);
i::Handle<i::Script> 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<i::Declaration*>* 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"));
}
......
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