Skip to content

Commit

Permalink
refactor(ast_tools): shorten code
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Oct 19, 2024
1 parent 85443d4 commit 66ed87a
Showing 1 changed file with 8 additions and 21 deletions.
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

0 comments on commit 66ed87a

Please sign in to comment.