| Index: src/ast/modules.cc
|
| diff --git a/src/ast/modules.cc b/src/ast/modules.cc
|
| index 6d8f35f39048057944beb600d472ec64e296053f..70772997b5890cc5ed0c961fe41d35e7f6086019 100644
|
| --- a/src/ast/modules.cc
|
| +++ b/src/ast/modules.cc
|
| @@ -134,19 +134,40 @@ void ModuleDescriptor::MakeIndirectExportsExplicit(Zone* zone) {
|
| }
|
| }
|
|
|
| +namespace {
|
| +
|
| +const ModuleDescriptor::Entry* BetterDuplicate(
|
| + const ModuleDescriptor::Entry* candidate,
|
| + ZoneMap<const AstRawString*, const ModuleDescriptor::Entry*>& export_names,
|
| + const ModuleDescriptor::Entry* current_duplicate) {
|
| + DCHECK_NOT_NULL(candidate->export_name);
|
| + DCHECK(candidate->location.IsValid());
|
| + auto insert_result =
|
| + export_names.insert(std::make_pair(candidate->export_name, candidate));
|
| + if (insert_result.second) return current_duplicate;
|
| + if (current_duplicate == nullptr) {
|
| + current_duplicate = insert_result.first->second;
|
| + }
|
| + return (candidate->location.beg_pos > current_duplicate->location.beg_pos)
|
| + ? candidate
|
| + : current_duplicate;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| const ModuleDescriptor::Entry* ModuleDescriptor::FindDuplicateExport(
|
| Zone* zone) const {
|
| - ZoneSet<const AstRawString*> export_names(zone);
|
| + const ModuleDescriptor::Entry* duplicate = nullptr;
|
| + ZoneMap<const AstRawString*, const ModuleDescriptor::Entry*> export_names(
|
| + zone);
|
| for (const auto& it : regular_exports_) {
|
| - const Entry* entry = it.second;
|
| - DCHECK_NOT_NULL(entry->export_name);
|
| - if (!export_names.insert(entry->export_name).second) return entry;
|
| + duplicate = BetterDuplicate(it.second, export_names, duplicate);
|
| }
|
| for (auto entry : special_exports_) {
|
| if (entry->export_name == nullptr) continue; // Star export.
|
| - if (!export_names.insert(entry->export_name).second) return entry;
|
| + duplicate = BetterDuplicate(entry, export_names, duplicate);
|
| }
|
| - return nullptr;
|
| + return duplicate;
|
| }
|
|
|
| bool ModuleDescriptor::Validate(ModuleScope* module_scope,
|
|
|