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 #ifndef V8_AST_MODULES_H_ | 5 #ifndef V8_AST_MODULES_H_ |
6 #define V8_AST_MODULES_H_ | 6 #define V8_AST_MODULES_H_ |
7 | 7 |
8 #include "src/parsing/scanner.h" // Only for Scanner::Location. | 8 #include "src/parsing/scanner.h" // Only for Scanner::Location. |
9 #include "src/pending-compilation-error-handler.h" | 9 #include "src/pending-compilation-error-handler.h" |
10 #include "src/zone-containers.h" | 10 #include "src/zone-containers.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 const AstRawString* export_name, const AstRawString* import_name, | 56 const AstRawString* export_name, const AstRawString* import_name, |
57 const AstRawString* module_request, const Scanner::Location loc, | 57 const AstRawString* module_request, const Scanner::Location loc, |
58 Zone* zone); | 58 Zone* zone); |
59 | 59 |
60 // export * from "foo.js"; | 60 // export * from "foo.js"; |
61 void AddStarExport( | 61 void AddStarExport( |
62 const AstRawString* module_request, const Scanner::Location loc, | 62 const AstRawString* module_request, const Scanner::Location loc, |
63 Zone* zone); | 63 Zone* zone); |
64 | 64 |
65 // Check if module is well-formed and report error if not. | 65 // Check if module is well-formed and report error if not. |
| 66 // Also canonicalize indirect exports. |
66 bool Validate(DeclarationScope* module_scope, | 67 bool Validate(DeclarationScope* module_scope, |
67 PendingCompilationErrorHandler* error_handler, | 68 PendingCompilationErrorHandler* error_handler, Zone* zone); |
68 Zone* zone) const; | |
69 | 69 |
70 struct ModuleEntry : public ZoneObject { | 70 struct ModuleEntry : public ZoneObject { |
71 const Scanner::Location location; | 71 const Scanner::Location location; |
72 const AstRawString* export_name; | 72 const AstRawString* export_name; |
73 const AstRawString* local_name; | 73 const AstRawString* local_name; |
74 const AstRawString* import_name; | 74 const AstRawString* import_name; |
75 const AstRawString* module_request; | 75 const AstRawString* module_request; |
76 | 76 |
77 explicit ModuleEntry(Scanner::Location loc) | 77 explicit ModuleEntry(Scanner::Location loc) |
78 : location(loc), | 78 : location(loc), |
79 export_name(nullptr), | 79 export_name(nullptr), |
80 local_name(nullptr), | 80 local_name(nullptr), |
81 import_name(nullptr), | 81 import_name(nullptr), |
82 module_request(nullptr) {} | 82 module_request(nullptr) {} |
83 }; | 83 }; |
84 | 84 |
85 const ZoneList<const ModuleEntry*>& exports() const { return exports_; } | 85 const ZoneList<ModuleEntry*>& exports() const { return exports_; } |
86 | 86 |
87 // Empty imports and namespace imports. | 87 // Empty imports and namespace imports. |
88 const ZoneList<const ModuleEntry*>& special_imports() const { | 88 const ZoneList<const ModuleEntry*>& special_imports() const { |
89 return special_imports_; | 89 return special_imports_; |
90 } | 90 } |
91 | 91 |
92 // All the remaining imports, indexed by local name. | 92 // All the remaining imports, indexed by local name. |
93 const ZoneMap<const AstRawString*, const ModuleEntry*>& regular_imports() | 93 const ZoneMap<const AstRawString*, const ModuleEntry*>& regular_imports() |
94 const { | 94 const { |
95 return regular_imports_; | 95 return regular_imports_; |
96 } | 96 } |
97 | 97 |
98 private: | 98 private: |
99 ZoneList<const ModuleEntry*> exports_; | 99 ZoneList<ModuleEntry*> exports_; |
100 ZoneList<const ModuleEntry*> special_imports_; | 100 ZoneList<const ModuleEntry*> special_imports_; |
101 ZoneMap<const AstRawString*, const ModuleEntry*> regular_imports_; | 101 ZoneMap<const AstRawString*, const ModuleEntry*> regular_imports_; |
| 102 |
| 103 // Find any implicitly indirect exports and make them explicit. |
| 104 // |
| 105 // An explicitly indirect export is an export entry arising from an export |
| 106 // statement of the following form: |
| 107 // export {a as c} from "X"; |
| 108 // An implicitly indirect export corresponds to |
| 109 // export {b as c}; |
| 110 // in the presence of an import statement of the form |
| 111 // import {a as b} from "X"; |
| 112 // This function finds such implicitly indirect export entries and rewrites |
| 113 // them by filling in the import name and module request, as well as nulling |
| 114 // out the local name. Effectively, it turns |
| 115 // import {a as b} from "X"; export {b as c}; |
| 116 // into: |
| 117 // import {a as b} from "X"; export {a as c} from "X"; |
| 118 // (The import entry is never deleted.) |
| 119 void MakeIndirectExportsExplicit(); |
102 }; | 120 }; |
103 | 121 |
104 } // namespace internal | 122 } // namespace internal |
105 } // namespace v8 | 123 } // namespace v8 |
106 | 124 |
107 #endif // V8_AST_MODULES_H_ | 125 #endif // V8_AST_MODULES_H_ |
OLD | NEW |