Skip to content

Commit 43f6de3

Browse files
committed
refactor(syntax): remove ModuleRecord::export_default_duplicated because it is a syntax error
1 parent 275d625 commit 43f6de3

File tree

5 files changed

+15
-54
lines changed

5 files changed

+15
-54
lines changed

crates/oxc_linter/src/module_record.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ pub struct ModuleRecord {
8989
/// `export default name`
9090
/// ^^^^^^^ span
9191
pub export_default: Option<Span>,
92-
93-
/// Duplicated span of `export default` for diagnostics
94-
pub export_default_duplicated: Vec<Span>,
9592
}
9693

9794
impl fmt::Debug for ModuleRecord {
@@ -117,7 +114,6 @@ impl fmt::Debug for ModuleRecord {
117114
.field("exported_bindings_duplicated", &self.exported_bindings_duplicated)
118115
.field("exported_bindings_from_star_export", &self.exported_bindings_from_star_export)
119116
.field("export_default", &self.export_default)
120-
.field("export_default_duplicated", &self.export_default_duplicated)
121117
.finish()
122118
}
123119
}
@@ -477,21 +473,7 @@ impl ModuleRecord {
477473
.iter()
478474
.map(NameSpan::from)
479475
.collect(),
480-
exported_bindings_from_star_export: other
481-
.exported_bindings_from_star_export
482-
.iter()
483-
.map(|(name, values)| {
484-
(
485-
PathBuf::from(name.as_str()),
486-
values
487-
.into_iter()
488-
.map(|v| CompactStr::from(v.as_str()))
489-
.collect::<Vec<_>>(),
490-
)
491-
})
492-
.collect(),
493476
export_default: other.export_default,
494-
export_default_duplicated: other.export_default_duplicated.iter().copied().collect(),
495477
..ModuleRecord::default()
496478
}
497479
}

crates/oxc_linter/src/rules/import/export.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,6 @@ impl Rule for Export {
108108
);
109109
}
110110
}
111-
112-
if !module_record.export_default_duplicated.is_empty() {
113-
let mut spans = module_record.export_default_duplicated.clone();
114-
if let Some(span) = module_record.export_default {
115-
spans.push(span);
116-
let labels = spans.into_iter().map(LabeledSpan::underline).collect::<Vec<_>>();
117-
ctx.diagnostic(
118-
OxcDiagnostic::warn("Multiple default exports.").with_labels(labels),
119-
);
120-
}
121-
}
122111
}
123112
}
124113

crates/oxc_linter/src/rules/import/no_default_export.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,12 @@ declare_oxc_lint!(
4646
impl Rule for NoDefaultExport {
4747
fn run_once(&self, ctx: &LintContext<'_>) {
4848
let module_record = ctx.module_record();
49-
write_diagnostic_optional(ctx, module_record.export_default);
50-
module_record.export_default_duplicated.iter().for_each(|it| write_diagnostic(ctx, *it));
51-
write_diagnostic_optional(ctx, module_record.exported_bindings.get("default").copied());
52-
}
53-
}
54-
55-
fn write_diagnostic(ctx: &LintContext<'_>, span: Span) {
56-
ctx.diagnostic(no_default_export_diagnostic(span));
57-
}
58-
59-
fn write_diagnostic_optional(ctx: &LintContext<'_>, span_option: Option<Span>) {
60-
if let Some(span) = span_option {
61-
write_diagnostic(ctx, span);
49+
if let Some(span) = module_record.export_default {
50+
ctx.diagnostic(no_default_export_diagnostic(span));
51+
}
52+
if let Some(span) = module_record.exported_bindings.get("default") {
53+
ctx.diagnostic(no_default_export_diagnostic(*span));
54+
}
6255
}
6356
}
6457

crates/oxc_parser/src/module_record.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ pub struct ModuleRecordBuilder<'a> {
1111
allocator: &'a Allocator,
1212
module_record: ModuleRecord<'a>,
1313
export_entries: Vec<ExportEntry<'a>>,
14+
export_default_duplicated: Vec<Span>,
1415
}
1516

1617
impl<'a> ModuleRecordBuilder<'a> {
1718
pub fn new(allocator: &'a Allocator) -> Self {
18-
Self { allocator, module_record: ModuleRecord::new(allocator), export_entries: vec![] }
19+
Self {
20+
allocator,
21+
module_record: ModuleRecord::new(allocator),
22+
export_entries: vec![],
23+
export_default_duplicated: vec![],
24+
}
1925
}
2026

2127
pub fn build(mut self) -> ModuleRecord<'a> {
@@ -36,7 +42,7 @@ impl<'a> ModuleRecordBuilder<'a> {
3642
errors.push(diagnostics::duplicate_export(&name_span.name, name_span.span, old_span));
3743
}
3844

39-
for span in &module_record.export_default_duplicated {
45+
for span in &self.export_default_duplicated {
4046
let old_span = module_record.export_default.unwrap();
4147
errors.push(diagnostics::duplicate_export("default", *span, old_span));
4248
}
@@ -88,7 +94,7 @@ impl<'a> ModuleRecordBuilder<'a> {
8894

8995
fn add_default_export(&mut self, span: Span) {
9096
if let Some(old_node) = self.module_record.export_default.replace(span) {
91-
self.module_record.export_default_duplicated.push(old_node);
97+
self.export_default_duplicated.push(old_node);
9298
}
9399
}
94100

crates/oxc_syntax/src/module_record.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,9 @@ pub struct ModuleRecord<'a> {
5959
/// Local duplicated exported bindings, for diagnostics
6060
pub exported_bindings_duplicated: Vec<'a, NameSpan<'a>>,
6161

62-
/// Reexported bindings from `export * from 'specifier'`
63-
/// Keyed by resolved path
64-
pub exported_bindings_from_star_export: FxHashMap<Atom<'a>, Vec<'a, Atom<'a>>>,
65-
6662
/// `export default name`
6763
/// ^^^^^^^ span
6864
pub export_default: Option<Span>,
69-
70-
/// Duplicated span of `export default` for diagnostics
71-
pub export_default_duplicated: Vec<'a, Span>,
7265
}
7366

7467
impl<'a> ModuleRecord<'a> {
@@ -83,9 +76,7 @@ impl<'a> ModuleRecord<'a> {
8376
star_export_entries: Vec::new_in(allocator),
8477
exported_bindings: FxHashMap::default(),
8578
exported_bindings_duplicated: Vec::new_in(allocator),
86-
exported_bindings_from_star_export: FxHashMap::default(),
8779
export_default: None,
88-
export_default_duplicated: Vec::new_in(allocator),
8980
}
9081
}
9182
}

0 commit comments

Comments
 (0)