mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
refactor(syntax): remove ModuleRecord::export_default_duplicated because it is a syntax error (#7576)
This commit is contained in:
parent
275d6256bb
commit
17663f55d3
5 changed files with 15 additions and 54 deletions
|
|
@ -89,9 +89,6 @@ pub struct ModuleRecord {
|
|||
/// `export default name`
|
||||
/// ^^^^^^^ span
|
||||
pub export_default: Option<Span>,
|
||||
|
||||
/// Duplicated span of `export default` for diagnostics
|
||||
pub export_default_duplicated: Vec<Span>,
|
||||
}
|
||||
|
||||
impl fmt::Debug for ModuleRecord {
|
||||
|
|
@ -117,7 +114,6 @@ impl fmt::Debug for ModuleRecord {
|
|||
.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)
|
||||
.field("export_default_duplicated", &self.export_default_duplicated)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
|
@ -477,21 +473,7 @@ impl ModuleRecord {
|
|||
.iter()
|
||||
.map(NameSpan::from)
|
||||
.collect(),
|
||||
exported_bindings_from_star_export: other
|
||||
.exported_bindings_from_star_export
|
||||
.iter()
|
||||
.map(|(name, values)| {
|
||||
(
|
||||
PathBuf::from(name.as_str()),
|
||||
values
|
||||
.into_iter()
|
||||
.map(|v| CompactStr::from(v.as_str()))
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
export_default: other.export_default,
|
||||
export_default_duplicated: other.export_default_duplicated.iter().copied().collect(),
|
||||
..ModuleRecord::default()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,17 +108,6 @@ impl Rule for Export {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
if !module_record.export_default_duplicated.is_empty() {
|
||||
let mut spans = module_record.export_default_duplicated.clone();
|
||||
if let Some(span) = module_record.export_default {
|
||||
spans.push(span);
|
||||
let labels = spans.into_iter().map(LabeledSpan::underline).collect::<Vec<_>>();
|
||||
ctx.diagnostic(
|
||||
OxcDiagnostic::warn("Multiple default exports.").with_labels(labels),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,19 +46,12 @@ declare_oxc_lint!(
|
|||
impl Rule for NoDefaultExport {
|
||||
fn run_once(&self, ctx: &LintContext<'_>) {
|
||||
let module_record = ctx.module_record();
|
||||
write_diagnostic_optional(ctx, module_record.export_default);
|
||||
module_record.export_default_duplicated.iter().for_each(|it| write_diagnostic(ctx, *it));
|
||||
write_diagnostic_optional(ctx, module_record.exported_bindings.get("default").copied());
|
||||
}
|
||||
}
|
||||
|
||||
fn write_diagnostic(ctx: &LintContext<'_>, span: Span) {
|
||||
ctx.diagnostic(no_default_export_diagnostic(span));
|
||||
}
|
||||
|
||||
fn write_diagnostic_optional(ctx: &LintContext<'_>, span_option: Option<Span>) {
|
||||
if let Some(span) = span_option {
|
||||
write_diagnostic(ctx, span);
|
||||
if let Some(span) = module_record.export_default {
|
||||
ctx.diagnostic(no_default_export_diagnostic(span));
|
||||
}
|
||||
if let Some(span) = module_record.exported_bindings.get("default") {
|
||||
ctx.diagnostic(no_default_export_diagnostic(*span));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,11 +11,17 @@ pub struct ModuleRecordBuilder<'a> {
|
|||
allocator: &'a Allocator,
|
||||
module_record: ModuleRecord<'a>,
|
||||
export_entries: Vec<ExportEntry<'a>>,
|
||||
export_default_duplicated: Vec<Span>,
|
||||
}
|
||||
|
||||
impl<'a> ModuleRecordBuilder<'a> {
|
||||
pub fn new(allocator: &'a Allocator) -> Self {
|
||||
Self { allocator, module_record: ModuleRecord::new(allocator), export_entries: vec![] }
|
||||
Self {
|
||||
allocator,
|
||||
module_record: ModuleRecord::new(allocator),
|
||||
export_entries: vec![],
|
||||
export_default_duplicated: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build(mut self) -> ModuleRecord<'a> {
|
||||
|
|
@ -36,7 +42,7 @@ impl<'a> ModuleRecordBuilder<'a> {
|
|||
errors.push(diagnostics::duplicate_export(&name_span.name, name_span.span, old_span));
|
||||
}
|
||||
|
||||
for span in &module_record.export_default_duplicated {
|
||||
for span in &self.export_default_duplicated {
|
||||
let old_span = module_record.export_default.unwrap();
|
||||
errors.push(diagnostics::duplicate_export("default", *span, old_span));
|
||||
}
|
||||
|
|
@ -88,7 +94,7 @@ impl<'a> ModuleRecordBuilder<'a> {
|
|||
|
||||
fn add_default_export(&mut self, span: Span) {
|
||||
if let Some(old_node) = self.module_record.export_default.replace(span) {
|
||||
self.module_record.export_default_duplicated.push(old_node);
|
||||
self.export_default_duplicated.push(old_node);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,16 +59,9 @@ pub struct ModuleRecord<'a> {
|
|||
/// Local duplicated exported bindings, for diagnostics
|
||||
pub exported_bindings_duplicated: Vec<'a, NameSpan<'a>>,
|
||||
|
||||
/// Reexported bindings from `export * from 'specifier'`
|
||||
/// Keyed by resolved path
|
||||
pub exported_bindings_from_star_export: FxHashMap<Atom<'a>, Vec<'a, Atom<'a>>>,
|
||||
|
||||
/// `export default name`
|
||||
/// ^^^^^^^ span
|
||||
pub export_default: Option<Span>,
|
||||
|
||||
/// Duplicated span of `export default` for diagnostics
|
||||
pub export_default_duplicated: Vec<'a, Span>,
|
||||
}
|
||||
|
||||
impl<'a> ModuleRecord<'a> {
|
||||
|
|
@ -83,9 +76,7 @@ impl<'a> ModuleRecord<'a> {
|
|||
star_export_entries: Vec::new_in(allocator),
|
||||
exported_bindings: FxHashMap::default(),
|
||||
exported_bindings_duplicated: Vec::new_in(allocator),
|
||||
exported_bindings_from_star_export: FxHashMap::default(),
|
||||
export_default: None,
|
||||
export_default_duplicated: Vec::new_in(allocator),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue