Skip to content
Merged
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
refactor(ast_tools): shorten code (#6678)
Follow-on after #6404. Pure refactor. Shorten code for deriving `ESTree` by reducing repetition.
  • Loading branch information
overlookmotel committed Oct 19, 2024
commit f0dd19a48fe01262d5361e4c939131373f3c15ff
29 changes: 8 additions & 21 deletions tasks/ast_tools/src/derives/estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,17 @@ impl Derive for DeriveESTree {
};
let ident = def.ident();

if def.has_lifetime() {
quote! {
impl<'a> Serialize for #ident<'a> {
#[allow(clippy::match_same_arms, unused_mut)]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,
{
#body
}
}
#ts_type_def
}
} else {
quote! {
impl Serialize for #ident {
#[allow(clippy::match_same_arms, unused_mut)]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
let lifetime = if def.has_lifetime() { quote!(<'a>) } else { TokenStream::new() };
quote! {
impl #lifetime Serialize for #ident #lifetime {
#[allow(clippy::match_same_arms, unused_mut)]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,
{
#body
}
{
#body
}
#ts_type_def
}
#ts_type_def
}
}

Expand Down