Skip to content

Commit 7427900

Browse files
committed
refactor(ast): re-order ExportDefaultDeclaration fields (#9348)
`ExportDefaultDeclaration` has a field `exported` which represents the `default` keyword. Our convention is that fields are ordered in source code order or evaluation order. Move `exported` field to before `declaration`.
1 parent 6a8f53f commit 7427900

File tree

15 files changed

+55
-55
lines changed

15 files changed

+55
-55
lines changed

crates/oxc_ast/src/ast/js.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2474,9 +2474,9 @@ pub struct ExportNamedDeclaration<'a> {
24742474
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
24752475
pub struct ExportDefaultDeclaration<'a> {
24762476
pub span: Span,
2477-
pub declaration: ExportDefaultDeclarationKind<'a>,
24782477
#[estree(skip)]
24792478
pub exported: ModuleExportName<'a>, // the `default` Keyword
2479+
pub declaration: ExportDefaultDeclarationKind<'a>,
24802480
}
24812481

24822482
/// Export All Declaration

crates/oxc_ast/src/generated/assert_layouts.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,8 @@ const _: () = {
724724
assert!(size_of::<ExportDefaultDeclaration>() == 72);
725725
assert!(align_of::<ExportDefaultDeclaration>() == 8);
726726
assert!(offset_of!(ExportDefaultDeclaration, span) == 0);
727-
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 8);
728-
assert!(offset_of!(ExportDefaultDeclaration, exported) == 24);
727+
assert!(offset_of!(ExportDefaultDeclaration, exported) == 8);
728+
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 56);
729729

730730
assert!(size_of::<ExportAllDeclaration>() == 112);
731731
assert!(align_of::<ExportAllDeclaration>() == 8);
@@ -2301,8 +2301,8 @@ const _: () = {
23012301
assert!(size_of::<ExportDefaultDeclaration>() == 44);
23022302
assert!(align_of::<ExportDefaultDeclaration>() == 4);
23032303
assert!(offset_of!(ExportDefaultDeclaration, span) == 0);
2304-
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 8);
2305-
assert!(offset_of!(ExportDefaultDeclaration, exported) == 16);
2304+
assert!(offset_of!(ExportDefaultDeclaration, exported) == 8);
2305+
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 36);
23062306

23072307
assert!(size_of::<ExportAllDeclaration>() == 68);
23082308
assert!(align_of::<ExportAllDeclaration>() == 4);

crates/oxc_ast/src/generated/ast_builder.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -6431,19 +6431,19 @@ impl<'a> AstBuilder<'a> {
64316431
///
64326432
/// ## Parameters
64336433
/// * `span`: The [`Span`] covering this node
6434-
/// * `declaration`
64356434
/// * `exported`
6435+
/// * `declaration`
64366436
#[inline]
64376437
pub fn module_declaration_export_default_declaration(
64386438
self,
64396439
span: Span,
6440-
declaration: ExportDefaultDeclarationKind<'a>,
64416440
exported: ModuleExportName<'a>,
6441+
declaration: ExportDefaultDeclarationKind<'a>,
64426442
) -> ModuleDeclaration<'a> {
64436443
ModuleDeclaration::ExportDefaultDeclaration(self.alloc_export_default_declaration(
64446444
span,
6445-
declaration,
64466445
exported,
6446+
declaration,
64476447
))
64486448
}
64496449

@@ -7060,16 +7060,16 @@ impl<'a> AstBuilder<'a> {
70607060
///
70617061
/// ## Parameters
70627062
/// * `span`: The [`Span`] covering this node
7063-
/// * `declaration`
70647063
/// * `exported`
7064+
/// * `declaration`
70657065
#[inline]
70667066
pub fn export_default_declaration(
70677067
self,
70687068
span: Span,
7069-
declaration: ExportDefaultDeclarationKind<'a>,
70707069
exported: ModuleExportName<'a>,
7070+
declaration: ExportDefaultDeclarationKind<'a>,
70717071
) -> ExportDefaultDeclaration<'a> {
7072-
ExportDefaultDeclaration { span, declaration, exported }
7072+
ExportDefaultDeclaration { span, exported, declaration }
70737073
}
70747074

70757075
/// Build an [`ExportDefaultDeclaration`], and store it in the memory arena.
@@ -7078,16 +7078,16 @@ impl<'a> AstBuilder<'a> {
70787078
///
70797079
/// ## Parameters
70807080
/// * `span`: The [`Span`] covering this node
7081-
/// * `declaration`
70827081
/// * `exported`
7082+
/// * `declaration`
70837083
#[inline]
70847084
pub fn alloc_export_default_declaration(
70857085
self,
70867086
span: Span,
7087-
declaration: ExportDefaultDeclarationKind<'a>,
70887087
exported: ModuleExportName<'a>,
7088+
declaration: ExportDefaultDeclarationKind<'a>,
70897089
) -> Box<'a, ExportDefaultDeclaration<'a>> {
7090-
Box::new_in(self.export_default_declaration(span, declaration, exported), self.allocator)
7090+
Box::new_in(self.export_default_declaration(span, exported, declaration), self.allocator)
70917091
}
70927092

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

crates/oxc_ast/src/generated/derive_clone_in.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2273,8 +2273,8 @@ impl<'new_alloc> CloneIn<'new_alloc> for ExportDefaultDeclaration<'_> {
22732273
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
22742274
ExportDefaultDeclaration {
22752275
span: CloneIn::clone_in(&self.span, allocator),
2276-
declaration: CloneIn::clone_in(&self.declaration, allocator),
22772276
exported: CloneIn::clone_in(&self.exported, allocator),
2277+
declaration: CloneIn::clone_in(&self.declaration, allocator),
22782278
}
22792279
}
22802280
}

crates/oxc_ast/src/generated/derive_content_eq.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1353,8 +1353,8 @@ impl ContentEq for ExportNamedDeclaration<'_> {
13531353

13541354
impl ContentEq for ExportDefaultDeclaration<'_> {
13551355
fn content_eq(&self, other: &Self) -> bool {
1356-
ContentEq::content_eq(&self.declaration, &other.declaration)
1357-
&& ContentEq::content_eq(&self.exported, &other.exported)
1356+
ContentEq::content_eq(&self.exported, &other.exported)
1357+
&& ContentEq::content_eq(&self.declaration, &other.declaration)
13581358
}
13591359
}
13601360

crates/oxc_ast/src/generated/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2811,8 +2811,8 @@ pub mod walk {
28112811
let kind = AstKind::ExportDefaultDeclaration(visitor.alloc(it));
28122812
visitor.enter_node(kind);
28132813
visitor.visit_span(&it.span);
2814-
visitor.visit_export_default_declaration_kind(&it.declaration);
28152814
visitor.visit_module_export_name(&it.exported);
2815+
visitor.visit_export_default_declaration_kind(&it.declaration);
28162816
visitor.leave_node(kind);
28172817
}
28182818

crates/oxc_ast/src/generated/visit_mut.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2921,8 +2921,8 @@ pub mod walk_mut {
29212921
let kind = AstType::ExportDefaultDeclaration;
29222922
visitor.enter_node(kind);
29232923
visitor.visit_span(&mut it.span);
2924-
visitor.visit_export_default_declaration_kind(&mut it.declaration);
29252924
visitor.visit_module_export_name(&mut it.exported);
2925+
visitor.visit_export_default_declaration_kind(&mut it.declaration);
29262926
visitor.leave_node(kind);
29272927
}
29282928

crates/oxc_isolated_declarations/src/module.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ impl<'a> IsolatedDeclarations<'a> {
6161
ModuleExportName::IdentifierName(self.ast.identifier_name(SPAN, "default"));
6262
let declaration = self.ast.module_declaration_export_default_declaration(
6363
decl.span,
64-
declaration,
6564
exported,
65+
declaration,
6666
);
6767
(var_decl, Statement::from(declaration))
6868
})

crates/oxc_parser/src/js/module.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl<'a> ParserImpl<'a> {
419419
};
420420
let exported = ModuleExportName::IdentifierName(exported);
421421
let span = self.end_span(span);
422-
Ok(self.ast.alloc_export_default_declaration(span, declaration, exported))
422+
Ok(self.ast.alloc_export_default_declaration(span, exported, declaration))
423423
}
424424

425425
// export ExportFromClause FromClause ;

crates/oxc_semantic/tests/fixtures/oxc/ts/exports/default/type-alias.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/ts/exports/default/type-alias
2727
"flags": "ReferenceFlags(Type)",
2828
"id": 0,
2929
"name": "A",
30-
"node_id": 6
30+
"node_id": 7
3131
}
3232
]
3333
}

crates/oxc_semantic/tests/fixtures/typescript-eslint/export/default-type.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/default-
2727
"flags": "ReferenceFlags(Read)",
2828
"id": 0,
2929
"name": "T",
30-
"node_id": 11
30+
"node_id": 12
3131
}
3232
]
3333
}

crates/oxc_semantic/tests/fixtures/typescript-eslint/export/default2.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/default2
1919
"flags": "ReferenceFlags(Read)",
2020
"id": 0,
2121
"name": "a",
22-
"node_id": 7
22+
"node_id": 8
2323
}
2424
]
2525
}

crates/oxc_transformer/src/decorator/legacy/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -903,10 +903,10 @@ impl<'a> LegacyDecorator<'a, '_> {
903903
) -> Statement<'a> {
904904
let export_default_class_reference = ctx.ast.module_declaration_export_default_declaration(
905905
SPAN,
906+
ctx.ast.module_export_name_identifier_name(SPAN, "default"),
906907
ExportDefaultDeclarationKind::Identifier(
907908
ctx.ast.alloc(class_binding.create_read_reference(ctx)),
908909
),
909-
ctx.ast.module_export_name_identifier_name(SPAN, "default"),
910910
);
911911
Statement::from(export_default_class_reference)
912912
}

crates/oxc_traverse/src/generated/ancestor.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ pub(crate) enum AncestorType {
182182
ExportNamedDeclarationSpecifiers = 159,
183183
ExportNamedDeclarationSource = 160,
184184
ExportNamedDeclarationWithClause = 161,
185-
ExportDefaultDeclarationDeclaration = 162,
186-
ExportDefaultDeclarationExported = 163,
185+
ExportDefaultDeclarationExported = 162,
186+
ExportDefaultDeclarationDeclaration = 163,
187187
ExportAllDeclarationExported = 164,
188188
ExportAllDeclarationSource = 165,
189189
ExportAllDeclarationWithClause = 166,
@@ -624,10 +624,10 @@ pub enum Ancestor<'a, 't> {
624624
AncestorType::ExportNamedDeclarationSource as u16,
625625
ExportNamedDeclarationWithClause(ExportNamedDeclarationWithoutWithClause<'a, 't>) =
626626
AncestorType::ExportNamedDeclarationWithClause as u16,
627-
ExportDefaultDeclarationDeclaration(ExportDefaultDeclarationWithoutDeclaration<'a, 't>) =
628-
AncestorType::ExportDefaultDeclarationDeclaration as u16,
629627
ExportDefaultDeclarationExported(ExportDefaultDeclarationWithoutExported<'a, 't>) =
630628
AncestorType::ExportDefaultDeclarationExported as u16,
629+
ExportDefaultDeclarationDeclaration(ExportDefaultDeclarationWithoutDeclaration<'a, 't>) =
630+
AncestorType::ExportDefaultDeclarationDeclaration as u16,
631631
ExportAllDeclarationExported(ExportAllDeclarationWithoutExported<'a, 't>) =
632632
AncestorType::ExportAllDeclarationExported as u16,
633633
ExportAllDeclarationSource(ExportAllDeclarationWithoutSource<'a, 't>) =
@@ -1404,8 +1404,8 @@ impl<'a, 't> Ancestor<'a, 't> {
14041404
pub fn is_export_default_declaration(self) -> bool {
14051405
matches!(
14061406
self,
1407-
Self::ExportDefaultDeclarationDeclaration(_)
1408-
| Self::ExportDefaultDeclarationExported(_)
1407+
Self::ExportDefaultDeclarationExported(_)
1408+
| Self::ExportDefaultDeclarationDeclaration(_)
14091409
)
14101410
}
14111411

@@ -2367,8 +2367,8 @@ impl<'a, 't> GetAddress for Ancestor<'a, 't> {
23672367
Self::ExportNamedDeclarationSpecifiers(a) => a.address(),
23682368
Self::ExportNamedDeclarationSource(a) => a.address(),
23692369
Self::ExportNamedDeclarationWithClause(a) => a.address(),
2370-
Self::ExportDefaultDeclarationDeclaration(a) => a.address(),
23712370
Self::ExportDefaultDeclarationExported(a) => a.address(),
2371+
Self::ExportDefaultDeclarationDeclaration(a) => a.address(),
23722372
Self::ExportAllDeclarationExported(a) => a.address(),
23732373
Self::ExportAllDeclarationSource(a) => a.address(),
23742374
Self::ExportAllDeclarationWithClause(a) => a.address(),
@@ -10009,19 +10009,19 @@ impl<'a, 't> GetAddress for ExportNamedDeclarationWithoutWithClause<'a, 't> {
1000910009

1001010010
pub(crate) const OFFSET_EXPORT_DEFAULT_DECLARATION_SPAN: usize =
1001110011
offset_of!(ExportDefaultDeclaration, span);
10012-
pub(crate) const OFFSET_EXPORT_DEFAULT_DECLARATION_DECLARATION: usize =
10013-
offset_of!(ExportDefaultDeclaration, declaration);
1001410012
pub(crate) const OFFSET_EXPORT_DEFAULT_DECLARATION_EXPORTED: usize =
1001510013
offset_of!(ExportDefaultDeclaration, exported);
10014+
pub(crate) const OFFSET_EXPORT_DEFAULT_DECLARATION_DECLARATION: usize =
10015+
offset_of!(ExportDefaultDeclaration, declaration);
1001610016

1001710017
#[repr(transparent)]
1001810018
#[derive(Clone, Copy, Debug)]
10019-
pub struct ExportDefaultDeclarationWithoutDeclaration<'a, 't>(
10019+
pub struct ExportDefaultDeclarationWithoutExported<'a, 't>(
1002010020
pub(crate) *const ExportDefaultDeclaration<'a>,
1002110021
pub(crate) PhantomData<&'t ()>,
1002210022
);
1002310023

10024-
impl<'a, 't> ExportDefaultDeclarationWithoutDeclaration<'a, 't> {
10024+
impl<'a, 't> ExportDefaultDeclarationWithoutExported<'a, 't> {
1002510025
#[inline]
1002610026
pub fn span(self) -> &'t Span {
1002710027
unsafe {
@@ -10030,15 +10030,15 @@ impl<'a, 't> ExportDefaultDeclarationWithoutDeclaration<'a, 't> {
1003010030
}
1003110031

1003210032
#[inline]
10033-
pub fn exported(self) -> &'t ModuleExportName<'a> {
10033+
pub fn declaration(self) -> &'t ExportDefaultDeclarationKind<'a> {
1003410034
unsafe {
10035-
&*((self.0 as *const u8).add(OFFSET_EXPORT_DEFAULT_DECLARATION_EXPORTED)
10036-
as *const ModuleExportName<'a>)
10035+
&*((self.0 as *const u8).add(OFFSET_EXPORT_DEFAULT_DECLARATION_DECLARATION)
10036+
as *const ExportDefaultDeclarationKind<'a>)
1003710037
}
1003810038
}
1003910039
}
1004010040

10041-
impl<'a, 't> GetAddress for ExportDefaultDeclarationWithoutDeclaration<'a, 't> {
10041+
impl<'a, 't> GetAddress for ExportDefaultDeclarationWithoutExported<'a, 't> {
1004210042
#[inline]
1004310043
fn address(&self) -> Address {
1004410044
Address::from_ptr(self.0)
@@ -10047,12 +10047,12 @@ impl<'a, 't> GetAddress for ExportDefaultDeclarationWithoutDeclaration<'a, 't> {
1004710047

1004810048
#[repr(transparent)]
1004910049
#[derive(Clone, Copy, Debug)]
10050-
pub struct ExportDefaultDeclarationWithoutExported<'a, 't>(
10050+
pub struct ExportDefaultDeclarationWithoutDeclaration<'a, 't>(
1005110051
pub(crate) *const ExportDefaultDeclaration<'a>,
1005210052
pub(crate) PhantomData<&'t ()>,
1005310053
);
1005410054

10055-
impl<'a, 't> ExportDefaultDeclarationWithoutExported<'a, 't> {
10055+
impl<'a, 't> ExportDefaultDeclarationWithoutDeclaration<'a, 't> {
1005610056
#[inline]
1005710057
pub fn span(self) -> &'t Span {
1005810058
unsafe {
@@ -10061,15 +10061,15 @@ impl<'a, 't> ExportDefaultDeclarationWithoutExported<'a, 't> {
1006110061
}
1006210062

1006310063
#[inline]
10064-
pub fn declaration(self) -> &'t ExportDefaultDeclarationKind<'a> {
10064+
pub fn exported(self) -> &'t ModuleExportName<'a> {
1006510065
unsafe {
10066-
&*((self.0 as *const u8).add(OFFSET_EXPORT_DEFAULT_DECLARATION_DECLARATION)
10067-
as *const ExportDefaultDeclarationKind<'a>)
10066+
&*((self.0 as *const u8).add(OFFSET_EXPORT_DEFAULT_DECLARATION_EXPORTED)
10067+
as *const ModuleExportName<'a>)
1006810068
}
1006910069
}
1007010070
}
1007110071

10072-
impl<'a, 't> GetAddress for ExportDefaultDeclarationWithoutExported<'a, 't> {
10072+
impl<'a, 't> GetAddress for ExportDefaultDeclarationWithoutDeclaration<'a, 't> {
1007310073
#[inline]
1007410074
fn address(&self) -> Address {
1007510075
Address::from_ptr(self.0)

crates/oxc_traverse/src/generated/walk.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -2994,22 +2994,22 @@ unsafe fn walk_export_default_declaration<'a, Tr: Traverse<'a>>(
29942994
ctx: &mut TraverseCtx<'a>,
29952995
) {
29962996
traverser.enter_export_default_declaration(&mut *node, ctx);
2997-
let pop_token = ctx.push_stack(Ancestor::ExportDefaultDeclarationDeclaration(
2998-
ancestor::ExportDefaultDeclarationWithoutDeclaration(node, PhantomData),
2997+
let pop_token = ctx.push_stack(Ancestor::ExportDefaultDeclarationExported(
2998+
ancestor::ExportDefaultDeclarationWithoutExported(node, PhantomData),
29992999
));
3000-
walk_export_default_declaration_kind(
3001-
traverser,
3002-
(node as *mut u8).add(ancestor::OFFSET_EXPORT_DEFAULT_DECLARATION_DECLARATION)
3003-
as *mut ExportDefaultDeclarationKind,
3004-
ctx,
3005-
);
3006-
ctx.retag_stack(AncestorType::ExportDefaultDeclarationExported);
30073000
walk_module_export_name(
30083001
traverser,
30093002
(node as *mut u8).add(ancestor::OFFSET_EXPORT_DEFAULT_DECLARATION_EXPORTED)
30103003
as *mut ModuleExportName,
30113004
ctx,
30123005
);
3006+
ctx.retag_stack(AncestorType::ExportDefaultDeclarationDeclaration);
3007+
walk_export_default_declaration_kind(
3008+
traverser,
3009+
(node as *mut u8).add(ancestor::OFFSET_EXPORT_DEFAULT_DECLARATION_DECLARATION)
3010+
as *mut ExportDefaultDeclarationKind,
3011+
ctx,
3012+
);
30133013
ctx.pop_stack(pop_token);
30143014
traverser.exit_export_default_declaration(&mut *node, ctx);
30153015
}

0 commit comments

Comments
 (0)