Index: src/parsing/parser.cc |
diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc |
index 18da7615f4557f94c76f35bd43f7e05c684a0985..9c76e20a261ffa54d0246164990873373bc7b00b 100644 |
--- a/src/parsing/parser.cc |
+++ b/src/parsing/parser.cc |
@@ -1154,8 +1154,7 @@ ZoneList<const Parser::NamedImport*>* Parser::ParseNamedImports( |
return nullptr; |
} |
- DeclareVariable(local_name, CONST, kNeedsInitialization, position(), |
- CHECK_OK); |
+ DeclareModuleImport(local_name, position(), CHECK_OK); |
NamedImport* import = new (zone()) NamedImport( |
import_name, local_name, scanner()->location()); |
@@ -1205,8 +1204,7 @@ void Parser::ParseImportDeclaration(bool* ok) { |
import_default_binding = |
ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID); |
import_default_binding_loc = scanner()->location(); |
- DeclareVariable(import_default_binding, CONST, kNeedsInitialization, pos, |
- CHECK_OK_VOID); |
+ DeclareModuleImport(import_default_binding, pos, CHECK_OK_VOID); |
} |
// Parse NameSpaceImport or NamedImports if present. |
@@ -1481,6 +1479,21 @@ Declaration* Parser::DeclareVariable(const AstRawString* name, |
return declaration; |
} |
+Declaration* Parser::DeclareModuleImport(const AstRawString* name, int pos, |
+ bool* ok) { |
+ DCHECK_EQ(MODULE_SCOPE, scope()->scope_type()); |
+ Declaration* decl = |
+ DeclareVariable(name, CONST, kNeedsInitialization, pos, CHECK_OK); |
+ // Allocate imports eagerly as hole check elimination logic in scope |
+ // analisys depends on identifying imports. |
+ // TODO(adamk): It's weird to allocate imports long before everything |
+ // else. We should find a different way of filtering out imports |
+ // during hole check elimination. |
+ decl->proxy()->var()->AllocateTo(VariableLocation::MODULE, |
+ Variable::kModuleImportIndex); |
+ return decl; |
+} |
+ |
Variable* Parser::Declare(Declaration* declaration, |
DeclarationDescriptor::Kind declaration_kind, |
VariableMode mode, InitializationFlag init, bool* ok, |