Skip to content

Commit

Permalink
pleaaaaaaaase Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
gbj committed Nov 27, 2023
1 parent 19f3997 commit 00af121
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 45 deletions.
17 changes: 3 additions & 14 deletions leptos_macro/src/component.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use attribute_derive::Attribute as AttributeDerive;
use convert_case::{
Case::{self, Pascal, Snake},
Case::{Pascal, Snake},
Casing,
};
use itertools::Itertools;
Expand Down Expand Up @@ -137,7 +137,6 @@ impl ToTokens for Model {
}
}

let module_name = module_name_from_fn_signature(&body.sig);
#[allow(clippy::redundant_clone)] // false positive
let body_name = body.sig.ident.clone();

Expand Down Expand Up @@ -236,12 +235,12 @@ impl ToTokens for Model {
let body_expr = if *is_island {
quote! {
::leptos::SharedContext::with_hydration(move || {
#module_name::#body_name(#prop_names)
#body_name(#prop_names)
})
}
} else {
quote! {
#module_name::#body_name(#prop_names)
#body_name(#prop_names)
}
};

Expand Down Expand Up @@ -1175,16 +1174,6 @@ fn is_valid_into_view_return_type(ty: &ReturnType) -> bool {
.any(|test| ty == test)
}

pub fn module_name_from_fn_signature(sig: &Signature) -> Ident {
let snake = &sig
.ident
.to_string()
.from_case(Case::Camel)
.to_case(Case::Snake);
let name = format!("component_module_{snake}");
Ident::new(&name, sig.ident.span())
}

pub fn unmodified_fn_name_from_fn_name(ident: &Ident) -> Ident {
Ident::new(&format!("__{ident}"), ident.span())
}
40 changes: 9 additions & 31 deletions leptos_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ impl Default for Mode {

mod params;
mod view;
use crate::component::{
module_name_from_fn_signature, unmodified_fn_name_from_fn_name,
};
use crate::component::unmodified_fn_name_from_fn_name;
use view::{client_template::render_template, render_view};
mod component;
mod server;
Expand Down Expand Up @@ -612,30 +610,20 @@ pub fn component(args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
span: unexpanded.vis.span(),
})
}
let module_name = module_name_from_fn_signature(&unexpanded.sig);
unexpanded.sig.ident =
unmodified_fn_name_from_fn_name(&unexpanded.sig.ident);
quote! {
#expanded
#[doc(hidden)]
mod #module_name {
use super::*;

#[allow(non_snake_case, dead_code, clippy::too_many_arguments)]
#unexpanded
}
#[allow(non_snake_case, dead_code, clippy::too_many_arguments)]
#unexpanded
}
} else if let Ok(mut dummy) = dummy {
let module_name = module_name_from_fn_signature(&dummy.sig);
dummy.sig.ident = unmodified_fn_name_from_fn_name(&dummy.sig.ident);
quote! {
#[doc(hidden)]
mod #module_name {
use super::*;

#[allow(non_snake_case, dead_code, clippy::too_many_arguments)]
#dummy
}
#[allow(non_snake_case, dead_code, clippy::too_many_arguments)]
#dummy
}
} else {
quote! {}
Expand Down Expand Up @@ -727,30 +715,20 @@ pub fn island(_args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
span: unexpanded.vis.span(),
})
}
let module_name = module_name_from_fn_signature(&unexpanded.sig);
unexpanded.sig.ident =
unmodified_fn_name_from_fn_name(&unexpanded.sig.ident);
quote! {
#expanded
#[doc(hidden)]
mod #module_name {
use super::*;

#[allow(non_snake_case, dead_code, clippy::too_many_arguments)]
#unexpanded
}
#[allow(non_snake_case, dead_code, clippy::too_many_arguments)]
#unexpanded
}
} else if let Ok(mut dummy) = dummy {
let module_name = module_name_from_fn_signature(&dummy.sig);
dummy.sig.ident = unmodified_fn_name_from_fn_name(&dummy.sig.ident);
quote! {
#[doc(hidden)]
mod #module_name {
use super::*;

#[allow(non_snake_case, dead_code, clippy::too_many_arguments)]
#dummy
}
#[allow(non_snake_case, dead_code, clippy::too_many_arguments)]
#dummy
}
} else {
quote! {}
Expand Down

0 comments on commit 00af121

Please sign in to comment.