Skip to content

Commit

Permalink
fix: emit original token stream when there are syntax errors in `#[co…
Browse files Browse the repository at this point in the history
…mponent]` or `#[island]` function signature (closes #2133) (#2134)
  • Loading branch information
gbj authored Dec 25, 2023
1 parent 9f4c480 commit 15946c6
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions leptos_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,12 @@ pub fn component(args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
false
};

let mut dummy = syn::parse::<DummyModel>(s.clone());
let Ok(mut dummy) = syn::parse::<DummyModel>(s.clone()) else {
return s;
};
let parse_result = syn::parse::<component::Model>(s);

if let (Ok(ref mut unexpanded), Ok(model)) = (&mut dummy, parse_result) {
if let (ref mut unexpanded, Ok(model)) = (&mut dummy, parse_result) {
let expanded = model.is_transparent(is_transparent).into_token_stream();
unexpanded.sig.ident =
unmodified_fn_name_from_fn_name(&unexpanded.sig.ident);
Expand All @@ -616,15 +618,13 @@ pub fn component(args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
#[allow(non_snake_case, dead_code, clippy::too_many_arguments)]
#unexpanded
}
} else if let Ok(mut dummy) = dummy {
} else {
dummy.sig.ident = unmodified_fn_name_from_fn_name(&dummy.sig.ident);
quote! {
#[doc(hidden)]
#[allow(non_snake_case, dead_code, clippy::too_many_arguments)]
#dummy
}
} else {
quote! {}
}
.into()
}
Expand Down Expand Up @@ -703,10 +703,12 @@ pub fn component(args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
#[proc_macro_error::proc_macro_error]
#[proc_macro_attribute]
pub fn island(_args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
let mut dummy = syn::parse::<DummyModel>(s.clone());
let Ok(mut dummy) = syn::parse::<DummyModel>(s.clone()) else {
return s;
};
let parse_result = syn::parse::<component::Model>(s);

if let (Ok(ref mut unexpanded), Ok(model)) = (&mut dummy, parse_result) {
if let (ref mut unexpanded, Ok(model)) = (&mut dummy, parse_result) {
let expanded = model.is_island().into_token_stream();
if !matches!(unexpanded.vis, Visibility::Public(_)) {
unexpanded.vis = Visibility::Public(Pub {
Expand All @@ -721,15 +723,13 @@ pub fn island(_args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
#[allow(non_snake_case, dead_code, clippy::too_many_arguments)]
#unexpanded
}
} else if let Ok(mut dummy) = dummy {
} else {
dummy.sig.ident = unmodified_fn_name_from_fn_name(&dummy.sig.ident);
quote! {
#[doc(hidden)]
#[allow(non_snake_case, dead_code, clippy::too_many_arguments)]
#dummy
}
} else {
quote! {}
}
.into()
}
Expand Down

0 comments on commit 15946c6

Please sign in to comment.