Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(629)

Side by Side Diff: src/ast/modules.cc

Issue 2223893004: [modules] Detect all indirect exports and represent them as such. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@modules-imports
Patch Set: Move call into Validate Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ast/modules.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ast/modules.h" 5 #include "src/ast/modules.h"
6 #include "src/ast/ast-value-factory.h" 6 #include "src/ast/ast-value-factory.h"
7 #include "src/ast/scopes.h" 7 #include "src/ast/scopes.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 74
75 void ModuleDescriptor::AddStarExport( 75 void ModuleDescriptor::AddStarExport(
76 const AstRawString* module_request, Scanner::Location loc, Zone* zone) { 76 const AstRawString* module_request, Scanner::Location loc, Zone* zone) {
77 DCHECK_NOT_NULL(module_request); 77 DCHECK_NOT_NULL(module_request);
78 ModuleEntry* entry = new (zone) ModuleEntry(loc); 78 ModuleEntry* entry = new (zone) ModuleEntry(loc);
79 entry->module_request = module_request; 79 entry->module_request = module_request;
80 exports_.Add(entry, zone); 80 exports_.Add(entry, zone);
81 } 81 }
82 82
83 void ModuleDescriptor::MakeIndirectExportsExplicit() {
84 for (auto entry : exports_) {
85 if (entry->export_name == nullptr) continue;
86 if (entry->import_name != nullptr) continue;
87 DCHECK_NOT_NULL(entry->local_name);
88 auto it = regular_imports_.find(entry->local_name);
89 if (it != regular_imports_.end()) {
90 // Found an indirect export.
91 DCHECK_NOT_NULL(it->second->module_request);
92 DCHECK_NOT_NULL(it->second->import_name);
93 entry->import_name = it->second->import_name;
94 entry->module_request = it->second->module_request;
95 entry->local_name = nullptr;
96 }
97 }
98 }
99
83 bool ModuleDescriptor::Validate(DeclarationScope* module_scope, 100 bool ModuleDescriptor::Validate(DeclarationScope* module_scope,
84 PendingCompilationErrorHandler* error_handler, 101 PendingCompilationErrorHandler* error_handler,
85 Zone* zone) const { 102 Zone* zone) {
86 DCHECK(module_scope->is_module_scope()); 103 DCHECK(module_scope->is_module_scope());
87 DCHECK_EQ(this, module_scope->module()); 104 DCHECK_EQ(this, module_scope->module());
88 DCHECK_NOT_NULL(error_handler); 105 DCHECK_NOT_NULL(error_handler);
89 106
90 // Report error iff there are duplicate exports. 107 // Report error iff there are duplicate exports.
91 { 108 {
92 ZoneAllocationPolicy allocator(zone); 109 ZoneAllocationPolicy allocator(zone);
93 ZoneHashMap* export_names = new (zone->New(sizeof(ZoneHashMap))) 110 ZoneHashMap* export_names = new (zone->New(sizeof(ZoneHashMap)))
94 ZoneHashMap(ZoneHashMap::PointersMatch, 111 ZoneHashMap(ZoneHashMap::PointersMatch,
95 ZoneHashMap::kDefaultHashMapCapacity, allocator); 112 ZoneHashMap::kDefaultHashMapCapacity, allocator);
(...skipping 17 matching lines...) Expand all
113 for (auto entry : exports_) { 130 for (auto entry : exports_) {
114 if (entry->local_name == nullptr) continue; 131 if (entry->local_name == nullptr) continue;
115 if (module_scope->LookupLocal(entry->local_name) == nullptr) { 132 if (module_scope->LookupLocal(entry->local_name) == nullptr) {
116 error_handler->ReportMessageAt( 133 error_handler->ReportMessageAt(
117 entry->location.beg_pos, entry->location.end_pos, 134 entry->location.beg_pos, entry->location.end_pos,
118 MessageTemplate::kModuleExportUndefined, entry->local_name); 135 MessageTemplate::kModuleExportUndefined, entry->local_name);
119 return false; 136 return false;
120 } 137 }
121 } 138 }
122 139
140 MakeIndirectExportsExplicit();
123 return true; 141 return true;
124 } 142 }
125 143
126 } // namespace internal 144 } // namespace internal
127 } // namespace v8 145 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/modules.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698