diff --git a/src/ast/modules.cc b/src/ast/modules.cc index 827980afcc..6d8f35f390 100644 --- a/src/ast/modules.cc +++ b/src/ast/modules.cc @@ -136,30 +136,17 @@ void ModuleDescriptor::MakeIndirectExportsExplicit(Zone* zone) { const ModuleDescriptor::Entry* ModuleDescriptor::FindDuplicateExport( Zone* zone) const { - const ModuleDescriptor::Entry* candidate = nullptr; ZoneSet export_names(zone); for (const auto& it : regular_exports_) { const Entry* entry = it.second; DCHECK_NOT_NULL(entry->export_name); - DCHECK(entry->location.IsValid()); - bool is_duplicate = !export_names.insert(entry->export_name).second; - if (is_duplicate && - (candidate == nullptr || - entry->location.beg_pos > candidate->location.beg_pos)) { - candidate = entry; - } + if (!export_names.insert(entry->export_name).second) return entry; } for (auto entry : special_exports_) { if (entry->export_name == nullptr) continue; // Star export. - DCHECK(entry->location.IsValid()); - bool is_duplicate = !export_names.insert(entry->export_name).second; - if (is_duplicate && - (candidate == nullptr || - entry->location.beg_pos > candidate->location.beg_pos)) { - candidate = entry; - } + if (!export_names.insert(entry->export_name).second) return entry; } - return candidate; + return nullptr; } bool ModuleDescriptor::Validate(ModuleScope* module_scope, diff --git a/src/ast/modules.h b/src/ast/modules.h index bdc31b24e6..0ed3509bc1 100644 --- a/src/ast/modules.h +++ b/src/ast/modules.h @@ -151,8 +151,8 @@ class ModuleDescriptor : public ZoneObject { ZoneMultimap regular_exports_; ZoneMap regular_imports_; - // If there are multiple export entries with the same export name, return the - // last of them (in source order). Otherwise return nullptr. + // If there are multiple export entries with the same export name, return one + // of them. Otherwise return nullptr. const Entry* FindDuplicateExport(Zone* zone) const; // Find any implicitly indirect exports and make them explicit. diff --git a/test/message/export-duplicate-as.js b/test/message/export-duplicate-as.js index 416180b093..49b52d4b17 100644 --- a/test/message/export-duplicate-as.js +++ b/test/message/export-duplicate-as.js @@ -4,6 +4,6 @@ // // MODULE -var a, b, c; +var a, b; export { a as c }; -export { a, b as c, c, b }; +export { a, b as c }; diff --git a/test/message/export-duplicate-as.out b/test/message/export-duplicate-as.out index 729de8a904..1726d9491a 100644 --- a/test/message/export-duplicate-as.out +++ b/test/message/export-duplicate-as.out @@ -2,6 +2,6 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. *%(basename)s:9: SyntaxError: Duplicate export of 'c' -export { a, b as c, c, b }; - ^ +export { a, b as c }; + ^ SyntaxError: Duplicate export of 'c' diff --git a/test/message/export-duplicate-default.js b/test/message/export-duplicate-default.js index de1a8807c1..72a54a45f4 100644 --- a/test/message/export-duplicate-default.js +++ b/test/message/export-duplicate-default.js @@ -5,5 +5,4 @@ // MODULE export default function f() {}; -export default 42; export default class C {}; diff --git a/test/message/export-duplicate-default.out b/test/message/export-duplicate-default.out index 685e289891..4c6b97a7a1 100644 --- a/test/message/export-duplicate-default.out +++ b/test/message/export-duplicate-default.out @@ -1,7 +1,7 @@ # Copyright 2015 the V8 project authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -*%(basename)s:9: SyntaxError: Duplicate export of 'default' +*%(basename)s:8: SyntaxError: Duplicate export of 'default' export default class C {}; ^^^^^^^ SyntaxError: Duplicate export of 'default' diff --git a/test/message/export-duplicate.js b/test/message/export-duplicate.js index 93011f0c1c..f45aefe13f 100644 --- a/test/message/export-duplicate.js +++ b/test/message/export-duplicate.js @@ -4,7 +4,6 @@ // // MODULE -var a, b, c; +var a, b; export { a }; export { a, b }; -export { b, c }; diff --git a/test/message/export-duplicate.out b/test/message/export-duplicate.out index 9811cb122c..e88779f580 100644 --- a/test/message/export-duplicate.out +++ b/test/message/export-duplicate.out @@ -1,7 +1,7 @@ # Copyright 2015 the V8 project authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -*%(basename)s:10: SyntaxError: Duplicate export of 'b' -export { b, c }; +*%(basename)s:9: SyntaxError: Duplicate export of 'a' +export { a, b }; ^ -SyntaxError: Duplicate export of 'b' +SyntaxError: Duplicate export of 'a' diff --git a/test/message/message.status b/test/message/message.status index e4db83db09..8916a26b9b 100644 --- a/test/message/message.status +++ b/test/message/message.status @@ -31,5 +31,7 @@ # escapes (we need to parse to distinguish octal escapes from valid # back-references). 'strict-octal-regexp': [SKIP], + # See issue v8:5358 + 'export-duplicate-default': [SKIP], }], # ALWAYS ]