[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}
This commit is contained in:
parent
cfc0dc4ef8
commit
da1f911c42
@ -136,17 +136,30 @@ void ModuleDescriptor::MakeIndirectExportsExplicit(Zone* zone) {
|
|||||||
|
|
||||||
const ModuleDescriptor::Entry* ModuleDescriptor::FindDuplicateExport(
|
const ModuleDescriptor::Entry* ModuleDescriptor::FindDuplicateExport(
|
||||||
Zone* zone) const {
|
Zone* zone) const {
|
||||||
|
const ModuleDescriptor::Entry* candidate = nullptr;
|
||||||
ZoneSet<const AstRawString*> export_names(zone);
|
ZoneSet<const AstRawString*> export_names(zone);
|
||||||
for (const auto& it : regular_exports_) {
|
for (const auto& it : regular_exports_) {
|
||||||
const Entry* entry = it.second;
|
const Entry* entry = it.second;
|
||||||
DCHECK_NOT_NULL(entry->export_name);
|
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_) {
|
for (auto entry : special_exports_) {
|
||||||
if (entry->export_name == nullptr) continue; // Star export.
|
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,
|
bool ModuleDescriptor::Validate(ModuleScope* module_scope,
|
||||||
|
@ -151,8 +151,8 @@ class ModuleDescriptor : public ZoneObject {
|
|||||||
ZoneMultimap<const AstRawString*, Entry*> regular_exports_;
|
ZoneMultimap<const AstRawString*, Entry*> regular_exports_;
|
||||||
ZoneMap<const AstRawString*, const Entry*> regular_imports_;
|
ZoneMap<const AstRawString*, const Entry*> regular_imports_;
|
||||||
|
|
||||||
// If there are multiple export entries with the same export name, return one
|
// If there are multiple export entries with the same export name, return the
|
||||||
// of them. Otherwise return nullptr.
|
// last of them (in source order). Otherwise return nullptr.
|
||||||
const Entry* FindDuplicateExport(Zone* zone) const;
|
const Entry* FindDuplicateExport(Zone* zone) const;
|
||||||
|
|
||||||
// Find any implicitly indirect exports and make them explicit.
|
// Find any implicitly indirect exports and make them explicit.
|
||||||
|
@ -4,6 +4,6 @@
|
|||||||
//
|
//
|
||||||
// MODULE
|
// MODULE
|
||||||
|
|
||||||
var a, b;
|
var a, b, c;
|
||||||
export { a as 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
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
# found in the LICENSE file.
|
# found in the LICENSE file.
|
||||||
*%(basename)s:9: SyntaxError: Duplicate export of 'c'
|
*%(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'
|
SyntaxError: Duplicate export of 'c'
|
||||||
|
@ -5,4 +5,5 @@
|
|||||||
// MODULE
|
// MODULE
|
||||||
|
|
||||||
export default function f() {};
|
export default function f() {};
|
||||||
|
export default 42;
|
||||||
export default class C {};
|
export default class C {};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Copyright 2015 the V8 project authors. All rights reserved.
|
# Copyright 2015 the V8 project authors. All rights reserved.
|
||||||
# Use of this source code is governed by a BSD-style license that can be
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
# found in the LICENSE file.
|
# 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 {};
|
export default class C {};
|
||||||
^^^^^^^
|
^^^^^^^
|
||||||
SyntaxError: Duplicate export of 'default'
|
SyntaxError: Duplicate export of 'default'
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
//
|
//
|
||||||
// MODULE
|
// MODULE
|
||||||
|
|
||||||
var a, b;
|
var a, b, c;
|
||||||
export { a };
|
export { a };
|
||||||
export { a, b };
|
export { a, b };
|
||||||
|
export { b, c };
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Copyright 2015 the V8 project authors. All rights reserved.
|
# Copyright 2015 the V8 project authors. All rights reserved.
|
||||||
# Use of this source code is governed by a BSD-style license that can be
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
# found in the LICENSE file.
|
# found in the LICENSE file.
|
||||||
*%(basename)s:9: SyntaxError: Duplicate export of 'a'
|
*%(basename)s:10: SyntaxError: Duplicate export of 'b'
|
||||||
export { a, 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
|
# escapes (we need to parse to distinguish octal escapes from valid
|
||||||
# back-references).
|
# back-references).
|
||||||
'strict-octal-regexp': [SKIP],
|
'strict-octal-regexp': [SKIP],
|
||||||
# See issue v8:5358
|
|
||||||
'export-duplicate-default': [SKIP],
|
|
||||||
}], # ALWAYS
|
}], # ALWAYS
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user