Skip to content
Merged
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
31 changes: 22 additions & 9 deletions crates/oxc_ast/src/ast/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,40 @@ pub struct TSThisParameter<'a> {
#[scope]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
#[estree(add_ts_def = "
interface TSEnumBody extends Span {
type: 'TSEnumBody';
members: TSEnumMember[];
}
")]
pub struct TSEnumDeclaration<'a> {
pub span: Span,
pub id: BindingIdentifier<'a>,
#[scope(enter_before)]
#[estree(rename = "body", via = TSEnumDeclarationBody)]
pub members: Vec<'a, TSEnumMember<'a>>,
pub body: TSEnumBody<'a>,
/// `true` for const enums
pub r#const: bool,
pub declare: bool,
pub scope_id: Cell<Option<ScopeId>>,
}

/// Enum Body
///
/// The body of a [`TSEnumDeclaration`].
///
/// ## Example
/// ```ts
/// enum Foo { A }
/// ^^^^^
/// enum Bar
/// { B }
/// ^^^^^
/// ```
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, Dummy, TakeIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
pub struct TSEnumBody<'a> {
pub span: Span,
pub members: Vec<'a, TSEnumMember<'a>>,
}

/// Enum Member
///
/// A member property in a [`TSEnumDeclaration`].
/// A member property in a [`TSEnumBody`].
///
/// ## Example
/// ```ts
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/ast_kind_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl AstKind<'_> {
Self::TSInstantiationExpression(_) => "TSInstantiationExpression".into(),

Self::TSEnumDeclaration(decl) => format!("TSEnumDeclaration({})", &decl.id.name).into(),

Self::TSEnumBody(_) => "TSEnumBody".into(),
Self::TSEnumMember(_) => "TSEnumMember".into(),

Self::TSImportEqualsDeclaration(_) => "TSImportEqualsDeclaration".into(),
Expand Down
30 changes: 20 additions & 10 deletions crates/oxc_ast/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,14 +911,19 @@ const _: () = {
assert!(offset_of!(TSThisParameter, this_span) == 8);
assert!(offset_of!(TSThisParameter, type_annotation) == 16);

assert!(size_of::<TSEnumDeclaration>() == 80);
assert!(size_of::<TSEnumDeclaration>() == 88);
assert!(align_of::<TSEnumDeclaration>() == 8);
assert!(offset_of!(TSEnumDeclaration, span) == 0);
assert!(offset_of!(TSEnumDeclaration, id) == 8);
assert!(offset_of!(TSEnumDeclaration, members) == 40);
assert!(offset_of!(TSEnumDeclaration, r#const) == 72);
assert!(offset_of!(TSEnumDeclaration, declare) == 73);
assert!(offset_of!(TSEnumDeclaration, scope_id) == 76);
assert!(offset_of!(TSEnumDeclaration, body) == 40);
assert!(offset_of!(TSEnumDeclaration, r#const) == 80);
assert!(offset_of!(TSEnumDeclaration, declare) == 81);
assert!(offset_of!(TSEnumDeclaration, scope_id) == 84);

assert!(size_of::<TSEnumBody>() == 40);
assert!(align_of::<TSEnumBody>() == 8);
assert!(offset_of!(TSEnumBody, span) == 0);
assert!(offset_of!(TSEnumBody, members) == 8);

assert!(size_of::<TSEnumMember>() == 40);
assert!(align_of::<TSEnumMember>() == 8);
Expand Down Expand Up @@ -2301,14 +2306,19 @@ const _: () = {
assert!(offset_of!(TSThisParameter, this_span) == 8);
assert!(offset_of!(TSThisParameter, type_annotation) == 16);

assert!(size_of::<TSEnumDeclaration>() == 52);
assert!(size_of::<TSEnumDeclaration>() == 60);
assert!(align_of::<TSEnumDeclaration>() == 4);
assert!(offset_of!(TSEnumDeclaration, span) == 0);
assert!(offset_of!(TSEnumDeclaration, id) == 8);
assert!(offset_of!(TSEnumDeclaration, members) == 28);
assert!(offset_of!(TSEnumDeclaration, r#const) == 44);
assert!(offset_of!(TSEnumDeclaration, declare) == 45);
assert!(offset_of!(TSEnumDeclaration, scope_id) == 48);
assert!(offset_of!(TSEnumDeclaration, body) == 28);
assert!(offset_of!(TSEnumDeclaration, r#const) == 52);
assert!(offset_of!(TSEnumDeclaration, declare) == 53);
assert!(offset_of!(TSEnumDeclaration, scope_id) == 56);

assert!(size_of::<TSEnumBody>() == 24);
assert!(align_of::<TSEnumBody>() == 4);
assert!(offset_of!(TSEnumBody, span) == 0);
assert!(offset_of!(TSEnumBody, members) == 8);

assert!(size_of::<TSEnumMember>() == 24);
assert!(align_of::<TSEnumMember>() == 4);
Expand Down
53 changes: 28 additions & 25 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4225,20 +4225,20 @@ impl<'a> AstBuilder<'a> {
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `id`
/// * `members`
/// * `body`
/// * `const`: `true` for const enums
/// * `declare`
#[inline]
pub fn declaration_ts_enum(
self,
span: Span,
id: BindingIdentifier<'a>,
members: Vec<'a, TSEnumMember<'a>>,
body: TSEnumBody<'a>,
r#const: bool,
declare: bool,
) -> Declaration<'a> {
Declaration::TSEnumDeclaration(
self.alloc_ts_enum_declaration(span, id, members, r#const, declare),
self.alloc_ts_enum_declaration(span, id, body, r#const, declare),
)
}

Expand All @@ -4249,7 +4249,7 @@ impl<'a> AstBuilder<'a> {
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `id`
/// * `members`
/// * `body`
/// * `const`: `true` for const enums
/// * `declare`
/// * `scope_id`
Expand All @@ -4258,14 +4258,14 @@ impl<'a> AstBuilder<'a> {
self,
span: Span,
id: BindingIdentifier<'a>,
members: Vec<'a, TSEnumMember<'a>>,
body: TSEnumBody<'a>,
r#const: bool,
declare: bool,
scope_id: ScopeId,
) -> Declaration<'a> {
Declaration::TSEnumDeclaration(
self.alloc_ts_enum_declaration_with_scope_id(
span, id, members, r#const, declare, scope_id,
span, id, body, r#const, declare, scope_id,
),
)
}
Expand Down Expand Up @@ -9642,19 +9642,19 @@ impl<'a> AstBuilder<'a> {
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `id`
/// * `members`
/// * `body`
/// * `const`: `true` for const enums
/// * `declare`
#[inline]
pub fn ts_enum_declaration(
self,
span: Span,
id: BindingIdentifier<'a>,
members: Vec<'a, TSEnumMember<'a>>,
body: TSEnumBody<'a>,
r#const: bool,
declare: bool,
) -> TSEnumDeclaration<'a> {
TSEnumDeclaration { span, id, members, r#const, declare, scope_id: Default::default() }
TSEnumDeclaration { span, id, body, r#const, declare, scope_id: Default::default() }
}

/// Build a [`TSEnumDeclaration`], and store it in the memory arena.
Expand All @@ -9665,19 +9665,19 @@ impl<'a> AstBuilder<'a> {
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `id`
/// * `members`
/// * `body`
/// * `const`: `true` for const enums
/// * `declare`
#[inline]
pub fn alloc_ts_enum_declaration(
self,
span: Span,
id: BindingIdentifier<'a>,
members: Vec<'a, TSEnumMember<'a>>,
body: TSEnumBody<'a>,
r#const: bool,
declare: bool,
) -> Box<'a, TSEnumDeclaration<'a>> {
Box::new_in(self.ts_enum_declaration(span, id, members, r#const, declare), self.allocator)
Box::new_in(self.ts_enum_declaration(span, id, body, r#const, declare), self.allocator)
}

/// Build a [`TSEnumDeclaration`] with `scope_id`.
Expand All @@ -9688,7 +9688,7 @@ impl<'a> AstBuilder<'a> {
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `id`
/// * `members`
/// * `body`
/// * `const`: `true` for const enums
/// * `declare`
/// * `scope_id`
Expand All @@ -9697,19 +9697,12 @@ impl<'a> AstBuilder<'a> {
self,
span: Span,
id: BindingIdentifier<'a>,
members: Vec<'a, TSEnumMember<'a>>,
body: TSEnumBody<'a>,
r#const: bool,
declare: bool,
scope_id: ScopeId,
) -> TSEnumDeclaration<'a> {
TSEnumDeclaration {
span,
id,
members,
r#const,
declare,
scope_id: Cell::new(Some(scope_id)),
}
TSEnumDeclaration { span, id, body, r#const, declare, scope_id: Cell::new(Some(scope_id)) }
}

/// Build a [`TSEnumDeclaration`] with `scope_id`, and store it in the memory arena.
Expand All @@ -9720,7 +9713,7 @@ impl<'a> AstBuilder<'a> {
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `id`
/// * `members`
/// * `body`
/// * `const`: `true` for const enums
/// * `declare`
/// * `scope_id`
Expand All @@ -9729,17 +9722,27 @@ impl<'a> AstBuilder<'a> {
self,
span: Span,
id: BindingIdentifier<'a>,
members: Vec<'a, TSEnumMember<'a>>,
body: TSEnumBody<'a>,
r#const: bool,
declare: bool,
scope_id: ScopeId,
) -> Box<'a, TSEnumDeclaration<'a>> {
Box::new_in(
self.ts_enum_declaration_with_scope_id(span, id, members, r#const, declare, scope_id),
self.ts_enum_declaration_with_scope_id(span, id, body, r#const, declare, scope_id),
self.allocator,
)
}

/// Build a [`TSEnumBody`].
///
/// ## Parameters
/// * `span`: The [`Span`] covering this node
/// * `members`
#[inline]
pub fn ts_enum_body(self, span: Span, members: Vec<'a, TSEnumMember<'a>>) -> TSEnumBody<'a> {
TSEnumBody { span, members }
}

/// Build a [`TSEnumMember`].
///
/// ## Parameters
Expand Down
Loading
Loading