Skip to content

Commit

Permalink
refactor(ast): remove IdentifierName from TSThisParameter
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel authored and DonIsaac committed Aug 29, 2024
1 parent 946c867 commit efd9f2f
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 166 deletions.
12 changes: 11 additions & 1 deletion crates/oxc_ast/src/ast/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,20 @@ export interface TSIndexSignatureName extends Span {
pub struct TSThisParameter<'a> {
#[serde(flatten)]
pub span: Span,
pub this: IdentifierName<'a>,
pub this: TSThisParameterKeyword,
pub type_annotation: Option<Box<'a, TSTypeAnnotation<'a>>>,
}

#[ast]
#[derive(Debug, Hash)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type", rename_all = "camelCase")]
pub struct TSThisParameterKeyword {
#[serde(flatten)]
pub span: Span,
}

/// Enum Declaration
///
/// `const_opt` enum `BindingIdentifier` { `EnumBody_opt` }
Expand Down
32 changes: 20 additions & 12 deletions crates/oxc_ast/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,11 +779,15 @@ const _: () = {
assert!(size_of::<ModuleExportName>() == 40usize);
assert!(align_of::<ModuleExportName>() == 8usize);

assert!(size_of::<TSThisParameter>() == 40usize);
assert!(size_of::<TSThisParameter>() == 24usize);
assert!(align_of::<TSThisParameter>() == 8usize);
assert!(offset_of!(TSThisParameter, span) == 0usize);
assert!(offset_of!(TSThisParameter, this) == 8usize);
assert!(offset_of!(TSThisParameter, type_annotation) == 32usize);
assert!(offset_of!(TSThisParameter, type_annotation) == 16usize);

assert!(size_of::<TSThisParameterKeyword>() == 8usize);
assert!(align_of::<TSThisParameterKeyword>() == 4usize);
assert!(offset_of!(TSThisParameterKeyword, span) == 0usize);

assert!(size_of::<TSEnumDeclaration>() == 80usize);
assert!(align_of::<TSEnumDeclaration>() == 8usize);
Expand Down Expand Up @@ -1031,13 +1035,13 @@ const _: () = {
assert!(offset_of!(TSIndexSignature, type_annotation) == 40usize);
assert!(offset_of!(TSIndexSignature, readonly) == 48usize);

assert!(size_of::<TSCallSignatureDeclaration>() == 72usize);
assert!(size_of::<TSCallSignatureDeclaration>() == 64usize);
assert!(align_of::<TSCallSignatureDeclaration>() == 8usize);
assert!(offset_of!(TSCallSignatureDeclaration, span) == 0usize);
assert!(offset_of!(TSCallSignatureDeclaration, this_param) == 8usize);
assert!(offset_of!(TSCallSignatureDeclaration, params) == 48usize);
assert!(offset_of!(TSCallSignatureDeclaration, return_type) == 56usize);
assert!(offset_of!(TSCallSignatureDeclaration, type_parameters) == 64usize);
assert!(offset_of!(TSCallSignatureDeclaration, params) == 40usize);
assert!(offset_of!(TSCallSignatureDeclaration, return_type) == 48usize);
assert!(offset_of!(TSCallSignatureDeclaration, type_parameters) == 56usize);

assert!(size_of::<TSMethodSignatureKind>() == 1usize);
assert!(align_of::<TSMethodSignatureKind>() == 1usize);
Expand Down Expand Up @@ -2180,11 +2184,15 @@ const _: () = {
assert!(size_of::<ModuleExportName>() == 24usize);
assert!(align_of::<ModuleExportName>() == 4usize);

assert!(size_of::<TSThisParameter>() == 28usize);
assert!(size_of::<TSThisParameter>() == 20usize);
assert!(align_of::<TSThisParameter>() == 4usize);
assert!(offset_of!(TSThisParameter, span) == 0usize);
assert!(offset_of!(TSThisParameter, this) == 8usize);
assert!(offset_of!(TSThisParameter, type_annotation) == 24usize);
assert!(offset_of!(TSThisParameter, type_annotation) == 16usize);

assert!(size_of::<TSThisParameterKeyword>() == 8usize);
assert!(align_of::<TSThisParameterKeyword>() == 4usize);
assert!(offset_of!(TSThisParameterKeyword, span) == 0usize);

assert!(size_of::<TSEnumDeclaration>() == 52usize);
assert!(align_of::<TSEnumDeclaration>() == 4usize);
Expand Down Expand Up @@ -2432,13 +2440,13 @@ const _: () = {
assert!(offset_of!(TSIndexSignature, type_annotation) == 24usize);
assert!(offset_of!(TSIndexSignature, readonly) == 28usize);

assert!(size_of::<TSCallSignatureDeclaration>() == 48usize);
assert!(size_of::<TSCallSignatureDeclaration>() == 44usize);
assert!(align_of::<TSCallSignatureDeclaration>() == 4usize);
assert!(offset_of!(TSCallSignatureDeclaration, span) == 0usize);
assert!(offset_of!(TSCallSignatureDeclaration, this_param) == 8usize);
assert!(offset_of!(TSCallSignatureDeclaration, params) == 36usize);
assert!(offset_of!(TSCallSignatureDeclaration, return_type) == 40usize);
assert!(offset_of!(TSCallSignatureDeclaration, type_parameters) == 44usize);
assert!(offset_of!(TSCallSignatureDeclaration, params) == 32usize);
assert!(offset_of!(TSCallSignatureDeclaration, return_type) == 36usize);
assert!(offset_of!(TSCallSignatureDeclaration, type_parameters) == 40usize);

assert!(size_of::<TSMethodSignatureKind>() == 1usize);
assert!(align_of::<TSMethodSignatureKind>() == 1usize);
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7884,7 +7884,7 @@ impl<'a> AstBuilder<'a> {
pub fn ts_this_parameter<T1>(
self,
span: Span,
this: IdentifierName<'a>,
this: TSThisParameterKeyword,
type_annotation: T1,
) -> TSThisParameter<'a>
where
Expand All @@ -7905,7 +7905,7 @@ impl<'a> AstBuilder<'a> {
pub fn alloc_ts_this_parameter<T1>(
self,
span: Span,
this: IdentifierName<'a>,
this: TSThisParameterKeyword,
type_annotation: T1,
) -> Box<'a, TSThisParameter<'a>>
where
Expand Down
7 changes: 7 additions & 0 deletions crates/oxc_ast/src/generated/derive_clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2264,6 +2264,13 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for TSThisParameter<'old_alloc>
}
}

impl<'alloc> CloneIn<'alloc> for TSThisParameterKeyword {
type Cloned = TSThisParameterKeyword;
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
TSThisParameterKeyword { span: self.span.clone_in(allocator) }
}
}

impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for TSEnumDeclaration<'old_alloc> {
type Cloned = TSEnumDeclaration<'new_alloc>;
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
Expand Down
7 changes: 7 additions & 0 deletions crates/oxc_ast/src/generated/derive_get_span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,13 @@ impl<'a> GetSpan for TSThisParameter<'a> {
}
}

impl GetSpan for TSThisParameterKeyword {
#[inline]
fn span(&self) -> Span {
self.span
}
}

impl<'a> GetSpan for TSEnumDeclaration<'a> {
#[inline]
fn span(&self) -> Span {
Expand Down
7 changes: 7 additions & 0 deletions crates/oxc_ast/src/generated/derive_get_span_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,13 @@ impl<'a> GetSpanMut for TSThisParameter<'a> {
}
}

impl GetSpanMut for TSThisParameterKeyword {
#[inline]
fn span_mut(&mut self) -> &mut Span {
&mut self.span
}
}

impl<'a> GetSpanMut for TSEnumDeclaration<'a> {
#[inline]
fn span_mut(&mut self) -> &mut Span {
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,6 @@ pub mod walk {
pub fn walk_ts_this_parameter<'a, V: Visit<'a>>(visitor: &mut V, it: &TSThisParameter<'a>) {
let kind = AstKind::TSThisParameter(visitor.alloc(it));
visitor.enter_node(kind);
visitor.visit_identifier_name(&it.this);
if let Some(type_annotation) = &it.type_annotation {
visitor.visit_ts_type_annotation(type_annotation);
}
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2174,7 +2174,6 @@ pub mod walk_mut {
) {
let kind = AstType::TSThisParameter;
visitor.enter_node(kind);
visitor.visit_identifier_name(&mut it.this);
if let Some(type_annotation) = &mut it.type_annotation {
visitor.visit_ts_type_annotation(type_annotation);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3156,7 +3156,7 @@ impl<'a> Gen for TSFunctionType<'a> {

impl<'a> Gen for TSThisParameter<'a> {
fn gen(&self, p: &mut Codegen, ctx: Context) {
self.this.gen(p, ctx);
p.print_str("this");
if let Some(type_annotation) = &self.type_annotation {
p.print_str(": ");
type_annotation.gen(p, ctx);
Expand Down
9 changes: 5 additions & 4 deletions crates/oxc_parser/src/ts/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,11 @@ impl<'a> ParserImpl<'a> {
let span = self.start_span();
self.parse_class_element_modifiers(true);
self.eat_decorators()?;
let this = {
let (span, name) = self.parse_identifier_kind(Kind::This);
self.ast.identifier_name(span, name)
};

let this_span = self.start_span();
self.bump_any();
let this = TSThisParameterKeyword { span: self.end_span(this_span) };

let type_annotation = self.parse_ts_type_annotation()?;
Ok(self.ast.ts_this_parameter(self.end_span(span), this, type_annotation))
}
Expand Down
Loading

0 comments on commit efd9f2f

Please sign in to comment.