Skip to content

Commit

Permalink
refactor(syntax): remove ModuleRecord::exported_bindings_duplicated
Browse files Browse the repository at this point in the history
… because it is a syntax error (#7577)
  • Loading branch information
Boshen committed Dec 2, 2024
1 parent 17663f5 commit d476660
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 43 deletions.
9 changes: 0 additions & 9 deletions crates/oxc_linter/src/module_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ pub struct ModuleRecord {
/// Local exported bindings
pub exported_bindings: FxHashMap<CompactStr, Span>,

/// Local duplicated exported bindings, for diagnostics
pub exported_bindings_duplicated: Vec<NameSpan>,

/// Reexported bindings from `export * from 'specifier'`
/// Keyed by resolved path
pub exported_bindings_from_star_export: FxDashMap<PathBuf, Vec<CompactStr>>,
Expand Down Expand Up @@ -111,7 +108,6 @@ impl fmt::Debug for ModuleRecord {
.field("indirect_export_entries", &self.indirect_export_entries)
.field("star_export_entries", &self.star_export_entries)
.field("exported_bindings", &self.exported_bindings)
.field("exported_bindings_duplicated", &self.exported_bindings_duplicated)
.field("exported_bindings_from_star_export", &self.exported_bindings_from_star_export)
.field("export_default", &self.export_default)
.finish()
Expand Down Expand Up @@ -468,11 +464,6 @@ impl ModuleRecord {
.iter()
.map(|(name, span)| (CompactStr::from(name.as_str()), *span))
.collect(),
exported_bindings_duplicated: other
.exported_bindings_duplicated
.iter()
.map(NameSpan::from)
.collect(),
export_default: other.export_default,
..ModuleRecord::default()
}
Expand Down
25 changes: 8 additions & 17 deletions crates/oxc_linter/src/rules/import/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ impl Rule for Export {
})
.collect::<Vec<_>>();

for name_span in &module_record.exported_bindings_duplicated {
if name == name_span.name() {
spans.push(name_span.span());
}
}

if !spans.is_empty() {
spans.push(*span);
let labels = spans.into_iter().map(LabeledSpan::underline).collect::<Vec<_>>();
Expand Down Expand Up @@ -344,16 +338,6 @@ fn test() {
// export const Foo = 'bar';
// export namespace Foo { }
// "),
(r#"
// declare module "a" {
// const Foo = 1;
// export {Foo as default};
// }
const Bar = 2;
export {Bar as default};
const Baz = 3;
export {Baz as default};
"#),
];

Tester::new(Export::NAME, Export::CATEGORY, pass, fail)
Expand All @@ -364,7 +348,14 @@ fn test() {

{
let pass = vec!["export * from './module'"];
let fail = vec![];
let fail = vec![
("
const Bar = 2;
export {Bar as default};
const Baz = 3;
export {Baz as default};
"),
];
Tester::new(Export::NAME, Export::CATEGORY, pass, fail)
.with_import_plugin(true)
.change_rule_path("export-star-4/index.js")
Expand Down
11 changes: 0 additions & 11 deletions crates/oxc_linter/src/snapshots/import_export.snap
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,3 @@ snapshot_kind: text
· ╰── It can not be redeclared here
4export namespace Foo { }
╰────

eslint-plugin-import(export): Multiple exports of name 'default'.
╭─[index.ts:7:32]
6const Bar = 2;
7export {Bar as default};
· ───────
8const Baz = 3;
9export {Baz as default};
· ───────
10
╰────
6 changes: 4 additions & 2 deletions crates/oxc_parser/src/module_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct ModuleRecordBuilder<'a> {
module_record: ModuleRecord<'a>,
export_entries: Vec<ExportEntry<'a>>,
export_default_duplicated: Vec<Span>,
exported_bindings_duplicated: Vec<NameSpan<'a>>,
}

impl<'a> ModuleRecordBuilder<'a> {
Expand All @@ -21,6 +22,7 @@ impl<'a> ModuleRecordBuilder<'a> {
module_record: ModuleRecord::new(allocator),
export_entries: vec![],
export_default_duplicated: vec![],
exported_bindings_duplicated: vec![],
}
}

Expand All @@ -37,7 +39,7 @@ impl<'a> ModuleRecordBuilder<'a> {
let module_record = &self.module_record;

// It is a Syntax Error if the ExportedNames of ModuleItemList contains any duplicate entries.
for name_span in &module_record.exported_bindings_duplicated {
for name_span in &self.exported_bindings_duplicated {
let old_span = module_record.exported_bindings[&name_span.name];
errors.push(diagnostics::duplicate_export(&name_span.name, name_span.span, old_span));
}
Expand Down Expand Up @@ -88,7 +90,7 @@ impl<'a> ModuleRecordBuilder<'a> {

fn add_export_binding(&mut self, name: Atom<'a>, span: Span) {
if let Some(old_node) = self.module_record.exported_bindings.insert(name.clone(), span) {
self.module_record.exported_bindings_duplicated.push(NameSpan::new(name, old_node));
self.exported_bindings_duplicated.push(NameSpan::new(name, old_node));
}
}

Expand Down
4 changes: 0 additions & 4 deletions crates/oxc_syntax/src/module_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ pub struct ModuleRecord<'a> {
/// Local exported bindings
pub exported_bindings: FxHashMap<Atom<'a>, Span>,

/// Local duplicated exported bindings, for diagnostics
pub exported_bindings_duplicated: Vec<'a, NameSpan<'a>>,

/// `export default name`
/// ^^^^^^^ span
pub export_default: Option<Span>,
Expand All @@ -75,7 +72,6 @@ impl<'a> ModuleRecord<'a> {
indirect_export_entries: Vec::new_in(allocator),
star_export_entries: Vec::new_in(allocator),
exported_bindings: FxHashMap::default(),
exported_bindings_duplicated: Vec::new_in(allocator),
export_default: None,
}
}
Expand Down

0 comments on commit d476660

Please sign in to comment.