OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast.h" | 10 #include "src/ast/ast.h" |
(...skipping 1570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1581 Scanner::Location module_namespace_binding_loc; | 1581 Scanner::Location module_namespace_binding_loc; |
1582 const ZoneList<const NamedImport*>* named_imports = nullptr; | 1582 const ZoneList<const NamedImport*>* named_imports = nullptr; |
1583 if (import_default_binding == nullptr || Check(Token::COMMA)) { | 1583 if (import_default_binding == nullptr || Check(Token::COMMA)) { |
1584 switch (peek()) { | 1584 switch (peek()) { |
1585 case Token::MUL: { | 1585 case Token::MUL: { |
1586 Consume(Token::MUL); | 1586 Consume(Token::MUL); |
1587 ExpectContextualKeyword(CStrVector("as"), CHECK_OK_VOID); | 1587 ExpectContextualKeyword(CStrVector("as"), CHECK_OK_VOID); |
1588 module_namespace_binding = | 1588 module_namespace_binding = |
1589 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID); | 1589 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID); |
1590 module_namespace_binding_loc = scanner()->location(); | 1590 module_namespace_binding_loc = scanner()->location(); |
| 1591 DeclareImport(module_namespace_binding, pos, CHECK_OK_VOID); |
1591 break; | 1592 break; |
1592 } | 1593 } |
1593 | 1594 |
1594 case Token::LBRACE: | 1595 case Token::LBRACE: |
1595 named_imports = ParseNamedImports(pos, CHECK_OK_VOID); | 1596 named_imports = ParseNamedImports(pos, CHECK_OK_VOID); |
1596 break; | 1597 break; |
1597 | 1598 |
1598 default: | 1599 default: |
1599 *ok = false; | 1600 *ok = false; |
1600 ReportUnexpectedToken(scanner()->current_token()); | 1601 ReportUnexpectedToken(scanner()->current_token()); |
1601 return; | 1602 return; |
1602 } | 1603 } |
1603 } | 1604 } |
1604 | 1605 |
1605 ExpectContextualKeyword(CStrVector("from"), CHECK_OK_VOID); | 1606 ExpectContextualKeyword(CStrVector("from"), CHECK_OK_VOID); |
1606 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK_VOID); | 1607 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK_VOID); |
1607 ExpectSemicolon(CHECK_OK_VOID); | 1608 ExpectSemicolon(CHECK_OK_VOID); |
1608 | 1609 |
1609 // Now that we have all the information, we can make the appropriate | 1610 // Now that we have all the information, we can make the appropriate |
1610 // declarations. | 1611 // declarations. |
1611 | 1612 |
1612 if (module_namespace_binding != nullptr) { | |
1613 module()->AddStarImport(module_namespace_binding, module_specifier, | |
1614 module_namespace_binding_loc, zone()); | |
1615 // TODO(neis): Create special immutable binding for the namespace object. | |
1616 } | |
1617 | |
1618 // TODO(neis): Would prefer to call DeclareImport below rather than above and | 1613 // TODO(neis): Would prefer to call DeclareImport below rather than above and |
1619 // in ParseNamedImports, but then a possible error message would point to the | 1614 // in ParseNamedImports, but then a possible error message would point to the |
1620 // wrong location. Maybe have a DeclareAt version of Declare that takes a | 1615 // wrong location. Maybe have a DeclareAt version of Declare that takes a |
1621 // location? | 1616 // location? |
1622 | 1617 |
| 1618 if (module_namespace_binding != nullptr) { |
| 1619 module()->AddStarImport(module_namespace_binding, module_specifier, |
| 1620 module_namespace_binding_loc, zone()); |
| 1621 // DeclareImport(module_namespace_binding, pos, CHECK_OK_VOID); |
| 1622 } |
| 1623 |
1623 if (import_default_binding != nullptr) { | 1624 if (import_default_binding != nullptr) { |
1624 module()->AddImport(ast_value_factory()->default_string(), | 1625 module()->AddImport(ast_value_factory()->default_string(), |
1625 import_default_binding, module_specifier, | 1626 import_default_binding, module_specifier, |
1626 import_default_binding_loc, zone()); | 1627 import_default_binding_loc, zone()); |
1627 // DeclareImport(import_default_binding, pos, CHECK_OK_VOID); | 1628 // DeclareImport(import_default_binding, pos, CHECK_OK_VOID); |
1628 } | 1629 } |
1629 | 1630 |
1630 if (named_imports != nullptr) { | 1631 if (named_imports != nullptr) { |
1631 if (named_imports->length() == 0) { | 1632 if (named_imports->length() == 0) { |
1632 module()->AddEmptyImport(module_specifier, scanner()->location(), zone()); | 1633 module()->AddEmptyImport(module_specifier, scanner()->location(), zone()); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1969 ? this->scope() | 1970 ? this->scope() |
1970 : this->scope()->GetDeclarationScope(); | 1971 : this->scope()->GetDeclarationScope(); |
1971 return scope->NewUnresolved(factory(), name, Variable::NORMAL, | 1972 return scope->NewUnresolved(factory(), name, Variable::NORMAL, |
1972 scanner()->location().beg_pos, | 1973 scanner()->location().beg_pos, |
1973 scanner()->location().end_pos); | 1974 scanner()->location().end_pos); |
1974 } | 1975 } |
1975 | 1976 |
1976 | 1977 |
1977 void Parser::DeclareImport(const AstRawString* local_name, int pos, bool* ok) { | 1978 void Parser::DeclareImport(const AstRawString* local_name, int pos, bool* ok) { |
1978 DCHECK_NOT_NULL(local_name); | 1979 DCHECK_NOT_NULL(local_name); |
1979 VariableProxy* proxy = NewUnresolved(local_name, IMPORT); | 1980 VariableProxy* proxy = NewUnresolved(local_name, CONST); |
1980 Declaration* declaration = | 1981 Declaration* declaration = |
1981 factory()->NewVariableDeclaration(proxy, IMPORT, scope(), pos); | 1982 factory()->NewVariableDeclaration(proxy, CONST, scope(), pos); |
1982 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK_VOID); | 1983 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK_VOID); |
1983 } | 1984 } |
1984 | 1985 |
1985 | 1986 |
1986 Variable* Parser::Declare(Declaration* declaration, | 1987 Variable* Parser::Declare(Declaration* declaration, |
1987 DeclarationDescriptor::Kind declaration_kind, | 1988 DeclarationDescriptor::Kind declaration_kind, |
1988 bool resolve, bool* ok, Scope* scope) { | 1989 bool resolve, bool* ok, Scope* scope) { |
1989 VariableProxy* proxy = declaration->proxy(); | 1990 VariableProxy* proxy = declaration->proxy(); |
1990 DCHECK(proxy->raw_name() != NULL); | 1991 DCHECK(proxy->raw_name() != NULL); |
1991 const AstRawString* name = proxy->raw_name(); | 1992 const AstRawString* name = proxy->raw_name(); |
(...skipping 5172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7164 node->Print(Isolate::Current()); | 7165 node->Print(Isolate::Current()); |
7165 } | 7166 } |
7166 #endif // DEBUG | 7167 #endif // DEBUG |
7167 | 7168 |
7168 #undef CHECK_OK | 7169 #undef CHECK_OK |
7169 #undef CHECK_OK_VOID | 7170 #undef CHECK_OK_VOID |
7170 #undef CHECK_FAILED | 7171 #undef CHECK_FAILED |
7171 | 7172 |
7172 } // namespace internal | 7173 } // namespace internal |
7173 } // namespace v8 | 7174 } // namespace v8 |
OLD | NEW |