Skip to content

Commit 9ceca68

Browse files
committed
refactor(ast)!: replace ExportDefaultDeclaration exported field with default_span
1 parent 5475075 commit 9ceca68

File tree

22 files changed

+181
-235
lines changed

22 files changed

+181
-235
lines changed

crates/oxc_ast/src/ast/js.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2607,8 +2607,9 @@ pub struct ExportNamedDeclaration<'a> {
26072607
#[estree(add_fields(exportKind = TsValue))]
26082608
pub struct ExportDefaultDeclaration<'a> {
26092609
pub span: Span,
2610+
/// Span of the `default` keyword
26102611
#[estree(skip)]
2611-
pub exported: ModuleExportName<'a>, // the `default` Keyword
2612+
pub default_span: Span,
26122613
pub declaration: ExportDefaultDeclarationKind<'a>,
26132614
}
26142615

crates/oxc_ast/src/generated/assert_layouts.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -818,11 +818,11 @@ const _: () = {
818818
assert!(offset_of!(ExportNamedDeclaration, with_clause) == 96);
819819

820820
// Padding: 0 bytes
821-
assert!(size_of::<ExportDefaultDeclaration>() == 80);
821+
assert!(size_of::<ExportDefaultDeclaration>() == 32);
822822
assert!(align_of::<ExportDefaultDeclaration>() == 8);
823823
assert!(offset_of!(ExportDefaultDeclaration, span) == 0);
824-
assert!(offset_of!(ExportDefaultDeclaration, exported) == 8);
825-
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 64);
824+
assert!(offset_of!(ExportDefaultDeclaration, default_span) == 8);
825+
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 16);
826826

827827
// Padding: 7 bytes
828828
assert!(size_of::<ExportAllDeclaration>() == 128);
@@ -2413,11 +2413,11 @@ const _: () = {
24132413
assert!(offset_of!(ExportNamedDeclaration, with_clause) == 60);
24142414

24152415
// Padding: 0 bytes
2416-
assert!(size_of::<ExportDefaultDeclaration>() == 48);
2416+
assert!(size_of::<ExportDefaultDeclaration>() == 24);
24172417
assert!(align_of::<ExportDefaultDeclaration>() == 4);
24182418
assert!(offset_of!(ExportDefaultDeclaration, span) == 0);
2419-
assert!(offset_of!(ExportDefaultDeclaration, exported) == 8);
2420-
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 40);
2419+
assert!(offset_of!(ExportDefaultDeclaration, default_span) == 8);
2420+
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 16);
24212421

24222422
// Padding: 3 bytes
24232423
assert!(size_of::<ExportAllDeclaration>() == 76);

crates/oxc_ast/src/generated/ast_builder.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7181,18 +7181,18 @@ impl<'a> AstBuilder<'a> {
71817181
///
71827182
/// ## Parameters
71837183
/// * `span`: The [`Span`] covering this node
7184-
/// * `exported`
7184+
/// * `default_span`: Span of the `default` keyword
71857185
/// * `declaration`
71867186
#[inline]
71877187
pub fn module_declaration_export_default_declaration(
71887188
self,
71897189
span: Span,
7190-
exported: ModuleExportName<'a>,
7190+
default_span: Span,
71917191
declaration: ExportDefaultDeclarationKind<'a>,
71927192
) -> ModuleDeclaration<'a> {
71937193
ModuleDeclaration::ExportDefaultDeclaration(self.alloc_export_default_declaration(
71947194
span,
7195-
exported,
7195+
default_span,
71967196
declaration,
71977197
))
71987198
}
@@ -7839,16 +7839,16 @@ impl<'a> AstBuilder<'a> {
78397839
///
78407840
/// ## Parameters
78417841
/// * `span`: The [`Span`] covering this node
7842-
/// * `exported`
7842+
/// * `default_span`: Span of the `default` keyword
78437843
/// * `declaration`
78447844
#[inline]
78457845
pub fn export_default_declaration(
78467846
self,
78477847
span: Span,
7848-
exported: ModuleExportName<'a>,
7848+
default_span: Span,
78497849
declaration: ExportDefaultDeclarationKind<'a>,
78507850
) -> ExportDefaultDeclaration<'a> {
7851-
ExportDefaultDeclaration { span, exported, declaration }
7851+
ExportDefaultDeclaration { span, default_span, declaration }
78527852
}
78537853

78547854
/// Build an [`ExportDefaultDeclaration`], and store it in the memory arena.
@@ -7858,16 +7858,19 @@ impl<'a> AstBuilder<'a> {
78587858
///
78597859
/// ## Parameters
78607860
/// * `span`: The [`Span`] covering this node
7861-
/// * `exported`
7861+
/// * `default_span`: Span of the `default` keyword
78627862
/// * `declaration`
78637863
#[inline]
78647864
pub fn alloc_export_default_declaration(
78657865
self,
78667866
span: Span,
7867-
exported: ModuleExportName<'a>,
7867+
default_span: Span,
78687868
declaration: ExportDefaultDeclarationKind<'a>,
78697869
) -> Box<'a, ExportDefaultDeclaration<'a>> {
7870-
Box::new_in(self.export_default_declaration(span, exported, declaration), self.allocator)
7870+
Box::new_in(
7871+
self.export_default_declaration(span, default_span, declaration),
7872+
self.allocator,
7873+
)
78717874
}
78727875

78737876
/// Build an [`ExportAllDeclaration`].

crates/oxc_ast/src/generated/derive_clone_in.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4362,15 +4362,15 @@ impl<'new_alloc> CloneIn<'new_alloc> for ExportDefaultDeclaration<'_> {
43624362
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
43634363
ExportDefaultDeclaration {
43644364
span: CloneIn::clone_in(&self.span, allocator),
4365-
exported: CloneIn::clone_in(&self.exported, allocator),
4365+
default_span: CloneIn::clone_in(&self.default_span, allocator),
43664366
declaration: CloneIn::clone_in(&self.declaration, allocator),
43674367
}
43684368
}
43694369

43704370
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
43714371
ExportDefaultDeclaration {
43724372
span: CloneIn::clone_in_with_semantic_ids(&self.span, allocator),
4373-
exported: CloneIn::clone_in_with_semantic_ids(&self.exported, allocator),
4373+
default_span: CloneIn::clone_in_with_semantic_ids(&self.default_span, allocator),
43744374
declaration: CloneIn::clone_in_with_semantic_ids(&self.declaration, allocator),
43754375
}
43764376
}

crates/oxc_ast/src/generated/derive_content_eq.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,8 +1360,7 @@ impl ContentEq for ExportNamedDeclaration<'_> {
13601360

13611361
impl ContentEq for ExportDefaultDeclaration<'_> {
13621362
fn content_eq(&self, other: &Self) -> bool {
1363-
ContentEq::content_eq(&self.exported, &other.exported)
1364-
&& ContentEq::content_eq(&self.declaration, &other.declaration)
1363+
ContentEq::content_eq(&self.declaration, &other.declaration)
13651364
}
13661365
}
13671366

crates/oxc_ast/src/generated/derive_dummy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ impl<'a> Dummy<'a> for ExportDefaultDeclaration<'a> {
14951495
fn dummy(allocator: &'a Allocator) -> Self {
14961496
Self {
14971497
span: Dummy::dummy(allocator),
1498-
exported: Dummy::dummy(allocator),
1498+
default_span: Dummy::dummy(allocator),
14991499
declaration: Dummy::dummy(allocator),
15001500
}
15011501
}

crates/oxc_ast_visit/src/generated/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2801,7 +2801,7 @@ pub mod walk {
28012801
let kind = AstKind::ExportDefaultDeclaration(visitor.alloc(it));
28022802
visitor.enter_node(kind);
28032803
visitor.visit_span(&it.span);
2804-
visitor.visit_module_export_name(&it.exported);
2804+
visitor.visit_span(&it.default_span);
28052805
visitor.visit_export_default_declaration_kind(&it.declaration);
28062806
visitor.leave_node(kind);
28072807
}

crates/oxc_ast_visit/src/generated/visit_mut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2911,7 +2911,7 @@ pub mod walk_mut {
29112911
let kind = AstType::ExportDefaultDeclaration;
29122912
visitor.enter_node(kind);
29132913
visitor.visit_span(&mut it.span);
2914-
visitor.visit_module_export_name(&mut it.exported);
2914+
visitor.visit_span(&mut it.default_span);
29152915
visitor.visit_export_default_declaration_kind(&mut it.declaration);
29162916
visitor.leave_node(kind);
29172917
}

crates/oxc_formatter/src/generated/ast_nodes.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8948,14 +8948,8 @@ impl<'a> GetSpan for AstNode<'a, ExportNamedDeclaration<'a>> {
89488948

89498949
impl<'a> AstNode<'a, ExportDefaultDeclaration<'a>> {
89508950
#[inline]
8951-
pub fn exported(&self) -> &AstNode<'a, ModuleExportName<'a>> {
8952-
let following_node = Some(SiblingNode::from(&self.inner.declaration));
8953-
self.allocator.alloc(AstNode {
8954-
inner: &self.inner.exported,
8955-
allocator: self.allocator,
8956-
parent: self.allocator.alloc(AstNodes::ExportDefaultDeclaration(transmute_self(self))),
8957-
following_node,
8958-
})
8951+
pub fn default_span(&self) -> Span {
8952+
self.inner.default_span
89598953
}
89608954

89618955
#[inline]

crates/oxc_isolated_declarations/src/module.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ impl<'a> IsolatedDeclarations<'a> {
5757
};
5858

5959
declaration.map(|(var_decl, declaration)| {
60-
let exported =
61-
ModuleExportName::IdentifierName(self.ast.identifier_name(SPAN, "default"));
6260
// When `var_decl` is Some, the comments are moved to the variable declaration, otherwise
6361
// keep the comments on the export default declaration to avoid losing them.
6462
// ```ts
@@ -82,7 +80,7 @@ impl<'a> IsolatedDeclarations<'a> {
8280

8381
let span = if var_decl.is_some() { SPAN } else { decl.span };
8482
let declaration =
85-
self.ast.module_declaration_export_default_declaration(span, exported, declaration);
83+
self.ast.module_declaration_export_default_declaration(span, SPAN, declaration);
8684
(var_decl, Statement::from(declaration))
8785
})
8886
}

0 commit comments

Comments
 (0)