fix: redundant spans (#2836)

Per https://docs.rs/quote/latest/quote/macro.quote.html#hygiene
regarding token hygiene.

> Any interpolated tokens preserve the Span information provided by their
> `ToTokens` implementation.

In many instances, the procedural macros are spanning tokens with their
own span redundantly.
This commit is contained in:
Chris 2024-08-16 20:25:56 -04:00 committed by GitHub
parent d9c8d4ff66
commit fcdfd617f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 35 deletions

View file

@ -78,10 +78,8 @@ pub(crate) fn component_to_tokens(
})
.unwrap_or_else(|| quote! { #name });
let value = quote_spanned!(value.span()=> { #value });
quote_spanned! {attr.span()=>
.#name(#[allow(unused_braces)] #value)
quote! {
.#name(#[allow(unused_braces)] { #value })
}
});
@ -262,30 +260,18 @@ pub(crate) fn component_to_tokens(
quote! {}
};
let name_ref = quote_spanned! {name.span()=>
&#name
};
let build = quote_spanned! {name.span()=>
.build()
};
let component_props_builder = quote_spanned! {name.span()=>
::leptos::component::component_props_builder(#name_ref #generics)
};
#[allow(unused_mut)] // used in debug
let mut component = quote_spanned! {node.span()=>
let mut component = quote! {
{
#[allow(unreachable_code)]
::leptos::component::component_view(
#[allow(clippy::needless_borrows_for_generic_args)]
#name_ref,
#component_props_builder
&#name,
::leptos::component::component_props_builder(&#name #generics)
#(#props)*
#(#slots)*
#children
#build
.build()
)
#spreads
}

View file

@ -695,20 +695,14 @@ pub(crate) fn event_type_and_handler(
let event_type = if is_custom {
event_type
} else if let Some(ev_name) = event_name_ident {
let span = ev_name.span();
quote_spanned! {
span => #ev_name
}
quote! { #ev_name }
} else {
event_type
};
let event_type = if is_force_undelegated {
let undelegated = if let Some(undelegated) = undelegated_ident {
let span = undelegated.span();
quote_spanned! {
span => #undelegated
}
quote! { #undelegated }
} else {
quote! { undelegated }
};

View file

@ -59,10 +59,8 @@ pub(crate) fn slot_to_tokens(
})
.unwrap_or_else(|| quote! { #name });
let value = quote_spanned!(value.span()=> { #value });
quote_spanned! {attr.span()=>
.#name(#[allow(unused_braces)] #value)
quote! {
.#name(#[allow(unused_braces)] { #value })
}
});
@ -136,8 +134,9 @@ pub(crate) fn slot_to_tokens(
items_to_bind.iter().map(|ident| quote! { #ident, });
let clonables = items_to_clone.iter().map(|ident| {
let ident_ref = quote_spanned!(ident.span()=> &#ident);
quote! { let #ident = ::core::clone::Clone::clone(#ident_ref); }
quote_spanned! {ident.span()=>
let #ident = ::core::clone::Clone::clone(&#ident);
}
});
if bindables.len() > 0 {
@ -169,7 +168,7 @@ pub(crate) fn slot_to_tokens(
.span();
let slot = Ident::new(&slot, span);
let value = if values.len() > 1 {
quote_spanned! {span=>
quote! {
::std::vec![
#(#values)*
]