Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2607,8 +2607,9 @@ pub struct ExportNamedDeclaration<'a> {
#[estree(add_fields(exportKind = TsValue))]
pub struct ExportDefaultDeclaration<'a> {
pub span: Span,
/// Span of the `default` keyword
#[estree(skip)]
pub exported: ModuleExportName<'a>, // the `default` Keyword
pub default_span: Span,
pub declaration: ExportDefaultDeclarationKind<'a>,
}

Expand Down
12 changes: 6 additions & 6 deletions crates/oxc_ast/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,11 +818,11 @@ const _: () = {
assert!(offset_of!(ExportNamedDeclaration, with_clause) == 96);

// Padding: 0 bytes
assert!(size_of::<ExportDefaultDeclaration>() == 80);
assert!(size_of::<ExportDefaultDeclaration>() == 32);
assert!(align_of::<ExportDefaultDeclaration>() == 8);
assert!(offset_of!(ExportDefaultDeclaration, span) == 0);
assert!(offset_of!(ExportDefaultDeclaration, exported) == 8);
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 64);
assert!(offset_of!(ExportDefaultDeclaration, default_span) == 8);
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 16);

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

// Padding: 0 bytes
assert!(size_of::<ExportDefaultDeclaration>() == 48);
assert!(size_of::<ExportDefaultDeclaration>() == 24);
assert!(align_of::<ExportDefaultDeclaration>() == 4);
assert!(offset_of!(ExportDefaultDeclaration, span) == 0);
assert!(offset_of!(ExportDefaultDeclaration, exported) == 8);
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 40);
assert!(offset_of!(ExportDefaultDeclaration, default_span) == 8);
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 16);

// Padding: 3 bytes
assert!(size_of::<ExportAllDeclaration>() == 76);
Expand Down
21 changes: 12 additions & 9 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7181,18 +7181,18 @@ impl<'a> AstBuilder<'a> {
///
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `exported`
/// * `default_span`: Span of the `default` keyword
/// * `declaration`
#[inline]
pub fn module_declaration_export_default_declaration(
self,
span: Span,
exported: ModuleExportName<'a>,
default_span: Span,
declaration: ExportDefaultDeclarationKind<'a>,
) -> ModuleDeclaration<'a> {
ModuleDeclaration::ExportDefaultDeclaration(self.alloc_export_default_declaration(
span,
exported,
default_span,
declaration,
))
}
Expand Down Expand Up @@ -7839,16 +7839,16 @@ impl<'a> AstBuilder<'a> {
///
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `exported`
/// * `default_span`: Span of the `default` keyword
/// * `declaration`
#[inline]
pub fn export_default_declaration(
self,
span: Span,
exported: ModuleExportName<'a>,
default_span: Span,
declaration: ExportDefaultDeclarationKind<'a>,
) -> ExportDefaultDeclaration<'a> {
ExportDefaultDeclaration { span, exported, declaration }
ExportDefaultDeclaration { span, default_span, declaration }
}

/// Build an [`ExportDefaultDeclaration`], and store it in the memory arena.
Expand All @@ -7858,16 +7858,19 @@ impl<'a> AstBuilder<'a> {
///
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `exported`
/// * `default_span`: Span of the `default` keyword
/// * `declaration`
#[inline]
pub fn alloc_export_default_declaration(
self,
span: Span,
exported: ModuleExportName<'a>,
default_span: Span,
declaration: ExportDefaultDeclarationKind<'a>,
) -> Box<'a, ExportDefaultDeclaration<'a>> {
Box::new_in(self.export_default_declaration(span, exported, declaration), self.allocator)
Box::new_in(
self.export_default_declaration(span, default_span, declaration),
self.allocator,
)
}

/// Build an [`ExportAllDeclaration`].
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_ast/src/generated/derive_clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4362,15 +4362,15 @@ impl<'new_alloc> CloneIn<'new_alloc> for ExportDefaultDeclaration<'_> {
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
ExportDefaultDeclaration {
span: CloneIn::clone_in(&self.span, allocator),
exported: CloneIn::clone_in(&self.exported, allocator),
default_span: CloneIn::clone_in(&self.default_span, allocator),
declaration: CloneIn::clone_in(&self.declaration, allocator),
}
}

fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
ExportDefaultDeclaration {
span: CloneIn::clone_in_with_semantic_ids(&self.span, allocator),
exported: CloneIn::clone_in_with_semantic_ids(&self.exported, allocator),
default_span: CloneIn::clone_in_with_semantic_ids(&self.default_span, allocator),
declaration: CloneIn::clone_in_with_semantic_ids(&self.declaration, allocator),
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_ast/src/generated/derive_content_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1360,8 +1360,7 @@ impl ContentEq for ExportNamedDeclaration<'_> {

impl ContentEq for ExportDefaultDeclaration<'_> {
fn content_eq(&self, other: &Self) -> bool {
ContentEq::content_eq(&self.exported, &other.exported)
&& ContentEq::content_eq(&self.declaration, &other.declaration)
ContentEq::content_eq(&self.declaration, &other.declaration)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/derive_dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ impl<'a> Dummy<'a> for ExportDefaultDeclaration<'a> {
fn dummy(allocator: &'a Allocator) -> Self {
Self {
span: Dummy::dummy(allocator),
exported: Dummy::dummy(allocator),
default_span: Dummy::dummy(allocator),
declaration: Dummy::dummy(allocator),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast_visit/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2801,7 +2801,7 @@ pub mod walk {
let kind = AstKind::ExportDefaultDeclaration(visitor.alloc(it));
visitor.enter_node(kind);
visitor.visit_span(&it.span);
visitor.visit_module_export_name(&it.exported);
visitor.visit_span(&it.default_span);
visitor.visit_export_default_declaration_kind(&it.declaration);
visitor.leave_node(kind);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast_visit/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2911,7 +2911,7 @@ pub mod walk_mut {
let kind = AstType::ExportDefaultDeclaration;
visitor.enter_node(kind);
visitor.visit_span(&mut it.span);
visitor.visit_module_export_name(&mut it.exported);
visitor.visit_span(&mut it.default_span);
visitor.visit_export_default_declaration_kind(&mut it.declaration);
visitor.leave_node(kind);
}
Expand Down
10 changes: 2 additions & 8 deletions crates/oxc_formatter/src/generated/ast_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8948,14 +8948,8 @@ impl<'a> GetSpan for AstNode<'a, ExportNamedDeclaration<'a>> {

impl<'a> AstNode<'a, ExportDefaultDeclaration<'a>> {
#[inline]
pub fn exported(&self) -> &AstNode<'a, ModuleExportName<'a>> {
let following_node = Some(SiblingNode::from(&self.inner.declaration));
self.allocator.alloc(AstNode {
inner: &self.inner.exported,
allocator: self.allocator,
parent: self.allocator.alloc(AstNodes::ExportDefaultDeclaration(transmute_self(self))),
following_node,
})
pub fn default_span(&self) -> Span {
self.inner.default_span
}

#[inline]
Expand Down
4 changes: 1 addition & 3 deletions crates/oxc_isolated_declarations/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ impl<'a> IsolatedDeclarations<'a> {
};

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

let span = if var_decl.is_some() { SPAN } else { decl.span };
let declaration =
self.ast.module_declaration_export_default_declaration(span, exported, declaration);
self.ast.module_declaration_export_default_declaration(span, SPAN, declaration);
(var_decl, Statement::from(declaration))
})
}
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_parser/src/js/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,11 @@ impl<'a> ParserImpl<'a> {
span: u32,
decorators: Vec<'a, Decorator<'a>>,
) -> Box<'a, ExportDefaultDeclaration<'a>> {
let exported = self.parse_keyword_identifier(Kind::Default);
let default_span = self.cur_token().span();
self.bump_remap(Kind::Default);
let declaration = self.parse_export_default_declaration_kind(decorators);
let exported = ModuleExportName::IdentifierName(exported);
let span = self.end_span(span);
self.ast.alloc_export_default_declaration(span, exported, declaration)
self.ast.alloc_export_default_declaration(span, default_span, declaration)
}

fn parse_export_default_declaration_kind(
Expand Down
4 changes: 1 addition & 3 deletions crates/oxc_parser/src/module_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,6 @@ impl<'a> ModuleRecordBuilder<'a> {
}

fn visit_export_default_declaration(&mut self, decl: &ExportDefaultDeclaration<'a>) {
let exported_name = &decl.exported;

let local_name = match &decl.declaration {
ExportDefaultDeclarationKind::Identifier(ident) => {
ExportLocalName::Default(NameSpan::new(ident.name, ident.span))
Expand All @@ -310,7 +308,7 @@ impl<'a> ModuleRecordBuilder<'a> {
span: decl.declaration.span(),
module_request: None,
import_name: ExportImportName::default(),
export_name: ExportExportName::Default(exported_name.span()),
export_name: ExportExportName::Default(decl.default_span),
local_name,
is_type: decl.is_typescript_syntax(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/ts/exports/default/type-alias
"flags": "ReferenceFlags(Type)",
"id": 0,
"name": "A",
"node_id": 6
"node_id": 5
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/default-
"flags": "ReferenceFlags(Read)",
"id": 0,
"name": "T",
"node_id": 11
"node_id": 10
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/export/default2
"flags": "ReferenceFlags(Read)",
"id": 0,
"name": "a",
"node_id": 7
"node_id": 6
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/decorator/legacy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ impl<'a> LegacyDecorator<'a, '_> {
) -> Statement<'a> {
let export_default_class_reference = ctx.ast.module_declaration_export_default_declaration(
SPAN,
ctx.ast.module_export_name_identifier_name(SPAN, "default"),
SPAN,
ExportDefaultDeclarationKind::Identifier(
ctx.ast.alloc(class_binding.create_read_reference(ctx)),
),
Expand Down
Loading
Loading