Skip to content

Commit

Permalink
rename inner fn to allow recursive components (i.e., referring to the…
Browse files Browse the repository at this point in the history
… component in the body of the component needs to refer to the expanded, not unmodified, version)
  • Loading branch information
gbj committed Nov 26, 2023
1 parent 77feaac commit a48b628
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions leptos_macro/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ impl ToTokens for Model {
quote! {}
};

let body_name = unmodified_fn_name_from_fn_name(&body_name);
let body_expr = if *is_island {
quote! {
::leptos::SharedContext::with_hydration(move || {
Expand Down Expand Up @@ -1169,3 +1170,7 @@ pub fn module_name_from_fn_signature(sig: &Signature) -> Ident {
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())
}
9 changes: 7 additions & 2 deletions leptos_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ impl Default for Mode {

mod params;
mod view;
use crate::component::module_name_from_fn_signature;
use crate::component::{
module_name_from_fn_signature, unmodified_fn_name_from_fn_name,
};
use view::{client_template::render_template, render_view};
mod component;
mod server;
Expand Down Expand Up @@ -610,6 +612,8 @@ pub fn component(args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
span: unexpanded.vis.span(),
})
}
unexpanded.sig.ident =
unmodified_fn_name_from_fn_name(&unexpanded.sig.ident);
let module_name = module_name_from_fn_signature(&unexpanded.sig);
quote! {
#expanded
Expand All @@ -621,7 +625,8 @@ pub fn component(args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
#unexpanded
}
}
} else if let Ok(dummy) = dummy {
} else if let Ok(mut dummy) = dummy {
dummy.sig.ident = unmodified_fn_name_from_fn_name(&dummy.sig.ident);
let module_name = module_name_from_fn_signature(&dummy.sig);
quote! {
#[doc(hidden)]
Expand Down

0 comments on commit a48b628

Please sign in to comment.