Commit da1f911c authored by neis's avatar neis Committed by Commit bot

[modules] Make duplicate export error deterministic.

In case of duplicate exports, always report the error for the very last
one.

R=adamk@chromium.org
BUG=v8:5358,v8:1569

Review-Url: https://codereview.chromium.org/2331003002
Cr-Commit-Position: refs/heads/master@{#39424}
parent cfc0dc4e
......@@ -136,17 +136,30 @@ void ModuleDescriptor::MakeIndirectExportsExplicit(Zone* zone) {
const ModuleDescriptor::Entry* ModuleDescriptor::FindDuplicateExport(
Zone* zone) const {
const ModuleDescriptor::Entry* candidate = nullptr;
ZoneSet<const AstRawString*> 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;
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;
}
}
for (auto entry : special_exports_) {
if (entry->export_name == nullptr) continue; // Star export.
if (!export_names.insert(entry->export_name).second) return entry;
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;
}
}
return nullptr;
return candidate;
}
bool ModuleDescriptor::Validate(ModuleScope* module_scope,
......
......@@ -151,8 +151,8 @@ class ModuleDescriptor : public ZoneObject {
ZoneMultimap<const AstRawString*, Entry*> regular_exports_;
ZoneMap<const AstRawString*, const Entry*> regular_imports_;
// If there are multiple export entries with the same export name, return one
// of them. Otherwise return nullptr.
// If there are multiple export entries with the same export name, return the
// last of them (in source order). Otherwise return nullptr.
const Entry* FindDuplicateExport(Zone* zone) const;
// Find any implicitly indirect exports and make them explicit.
......
......@@ -4,6 +4,6 @@
//
// MODULE
var a, b;
var a, b, c;
export { a as c };
export { a, b as c };
export { a, b as c, c, b };
......@@ -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 };
^
export { a, b as c, c, b };
^
SyntaxError: Duplicate export of 'c'
......@@ -5,4 +5,5 @@
// MODULE
export default function f() {};
export default 42;
export default class C {};
# 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:8: SyntaxError: Duplicate export of 'default'
*%(basename)s:9: SyntaxError: Duplicate export of 'default'
export default class C {};
^^^^^^^
SyntaxError: Duplicate export of 'default'
......@@ -4,6 +4,7 @@
//
// MODULE
var a, b;
var a, b, c;
export { a };
export { a, b };
export { b, c };
# 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 'a'
export { a, b };
*%(basename)s:10: SyntaxError: Duplicate export of 'b'
export { b, c };
^
SyntaxError: Duplicate export of 'a'
SyntaxError: Duplicate export of 'b'
......@@ -31,7 +31,5 @@
# 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
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment