mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
Fix macro hygine issues (#2585)
* no_implicit_prelude in macro tests * #[automatically_derived] and #[doc(hidden)] * Span::call_site() -> Span::mixed_site()
This commit is contained in:
parent
8ca7ceb34f
commit
2f3b90ce2c
@ -48,7 +48,7 @@ impl ToTokens for PropsBuilder<'_> {
|
|||||||
|
|
||||||
// Each builder step implements the `BuilderStep` trait and `step_generics` is used to
|
// Each builder step implements the `BuilderStep` trait and `step_generics` is used to
|
||||||
// enforce that.
|
// enforce that.
|
||||||
let step_generic_param = Ident::new("YEW_PROPS_BUILDER_STEP", Span::call_site());
|
let step_generic_param = Ident::new("YEW_PROPS_BUILDER_STEP", Span::mixed_site());
|
||||||
let step_generics =
|
let step_generics =
|
||||||
with_param_bounds(generics, step_generic_param.clone(), (*step_trait).clone());
|
with_param_bounds(generics, step_generic_param.clone(), (*step_trait).clone());
|
||||||
|
|
||||||
@ -62,7 +62,10 @@ impl ToTokens for PropsBuilder<'_> {
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#vis trait #step_trait {}
|
#vis trait #step_trait {}
|
||||||
|
|
||||||
#(impl #step_trait for #step_names {})*
|
#(
|
||||||
|
#[automatically_derived]
|
||||||
|
impl #step_trait for #step_names {}
|
||||||
|
)*
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#vis struct #builder_name #step_generics
|
#vis struct #builder_name #step_generics
|
||||||
@ -74,6 +77,7 @@ impl ToTokens for PropsBuilder<'_> {
|
|||||||
|
|
||||||
#impl_steps
|
#impl_steps
|
||||||
|
|
||||||
|
#[automatically_derived]
|
||||||
impl #impl_generics #builder_name<#generic_args> #where_clause {
|
impl #impl_generics #builder_name<#generic_args> #where_clause {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#vis fn build(self) -> #props_name #ty_generics {
|
#vis fn build(self) -> #props_name #ty_generics {
|
||||||
@ -189,6 +193,7 @@ impl PropsBuilder<'_> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
token_stream.extend(quote! {
|
token_stream.extend(quote! {
|
||||||
|
#[automatically_derived]
|
||||||
#( #extra_attrs )*
|
#( #extra_attrs )*
|
||||||
impl #impl_generics #builder_name<#current_step_arguments> #where_clause {
|
impl #impl_generics #builder_name<#current_step_arguments> #where_clause {
|
||||||
#(#optional_prop_fn)*
|
#(#optional_prop_fn)*
|
||||||
|
|||||||
@ -191,7 +191,7 @@ impl PropField {
|
|||||||
Ok(PropAttr::Option)
|
Ok(PropAttr::Option)
|
||||||
} else {
|
} else {
|
||||||
let ident = named_field.ident.as_ref().unwrap();
|
let ident = named_field.ident.as_ref().unwrap();
|
||||||
let wrapped_name = format_ident!("{}_wrapper", ident, span = Span::call_site());
|
let wrapped_name = format_ident!("{}_wrapper", ident, span = Span::mixed_site());
|
||||||
Ok(PropAttr::Required { wrapped_name })
|
Ok(PropAttr::Required { wrapped_name })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -84,7 +84,7 @@ fn new_param_bounds(param_ident: Ident, param_bounds: Ident) -> GenericParam {
|
|||||||
GenericParam::Type(TypeParam {
|
GenericParam::Type(TypeParam {
|
||||||
attrs: Vec::new(),
|
attrs: Vec::new(),
|
||||||
ident: param_ident,
|
ident: param_ident,
|
||||||
colon_token: Some(Token)),
|
colon_token: Some(Token)),
|
||||||
bounds: param_bounds,
|
bounds: param_bounds,
|
||||||
eq_token: None,
|
eq_token: None,
|
||||||
default: None,
|
default: None,
|
||||||
|
|||||||
@ -80,7 +80,7 @@ impl ToTokens for DerivePropsInput {
|
|||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
// The wrapper is a new struct which wraps required props in `Option`
|
// The wrapper is a new struct which wraps required props in `Option`
|
||||||
let wrapper_name = format_ident!("{}Wrapper", props_name, span = Span::call_site());
|
let wrapper_name = format_ident!("{}Wrapper", props_name, span = Span::mixed_site());
|
||||||
let wrapper = PropsWrapper::new(
|
let wrapper = PropsWrapper::new(
|
||||||
&wrapper_name,
|
&wrapper_name,
|
||||||
generics,
|
generics,
|
||||||
@ -90,8 +90,8 @@ impl ToTokens for DerivePropsInput {
|
|||||||
tokens.extend(wrapper.into_token_stream());
|
tokens.extend(wrapper.into_token_stream());
|
||||||
|
|
||||||
// The builder will only build if all required props have been set
|
// The builder will only build if all required props have been set
|
||||||
let builder_name = format_ident!("{}Builder", props_name, span = Span::call_site());
|
let builder_name = format_ident!("{}Builder", props_name, span = Span::mixed_site());
|
||||||
let builder_step = format_ident!("{}BuilderStep", props_name, span = Span::call_site());
|
let builder_step = format_ident!("{}BuilderStep", props_name, span = Span::mixed_site());
|
||||||
let builder = PropsBuilder::new(
|
let builder = PropsBuilder::new(
|
||||||
&builder_name,
|
&builder_name,
|
||||||
&builder_step,
|
&builder_step,
|
||||||
|
|||||||
@ -26,6 +26,7 @@ impl ToTokens for PropsWrapper<'_> {
|
|||||||
let wrapper_default_setters = self.default_setters();
|
let wrapper_default_setters = self.default_setters();
|
||||||
|
|
||||||
let wrapper = quote! {
|
let wrapper = quote! {
|
||||||
|
#[doc(hidden)]
|
||||||
#(#extra_attrs)*
|
#(#extra_attrs)*
|
||||||
struct #wrapper_name #generics
|
struct #wrapper_name #generics
|
||||||
#where_clause
|
#where_clause
|
||||||
@ -33,6 +34,7 @@ impl ToTokens for PropsWrapper<'_> {
|
|||||||
#(#wrapper_field_defs)*
|
#(#wrapper_field_defs)*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[automatically_derived]
|
||||||
impl #impl_generics ::std::default::Default for #wrapper_name #ty_generics #where_clause {
|
impl #impl_generics ::std::default::Default for #wrapper_name #ty_generics #where_clause {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
#wrapper_name #turbofish_generics {
|
#wrapper_name #turbofish_generics {
|
||||||
|
|||||||
@ -162,6 +162,7 @@ pub fn hook_impl(hook: HookFn) -> syn::Result<TokenStream> {
|
|||||||
#args_ident: (#(#input_types,)*),
|
#args_ident: (#(#input_types,)*),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[automatically_derived]
|
||||||
impl #impl_generics ::yew::functional::Hook for #hook_struct_name #ty_generics #where_clause {
|
impl #impl_generics ::yew::functional::Hook for #hook_struct_name #ty_generics #where_clause {
|
||||||
type Output = #output_type;
|
type Output = #output_type;
|
||||||
|
|
||||||
@ -172,6 +173,7 @@ pub fn hook_impl(hook: HookFn) -> syn::Result<TokenStream> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[automatically_derived]
|
||||||
impl #impl_generics #hook_struct_name #ty_generics #where_clause {
|
impl #impl_generics #hook_struct_name #ty_generics #where_clause {
|
||||||
fn new(#inputs) -> Self {
|
fn new(#inputs) -> Self {
|
||||||
#hook_struct_name {
|
#hook_struct_name {
|
||||||
|
|||||||
@ -166,7 +166,7 @@ impl HtmlComponent {
|
|||||||
if punct.as_char() == '>' {
|
if punct.as_char() == '>' {
|
||||||
break;
|
break;
|
||||||
} else if punct.as_char() == ',' {
|
} else if punct.as_char() == ',' {
|
||||||
args.push_punct(Token))
|
args.push_punct(Token))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -174,9 +174,9 @@ impl HtmlComponent {
|
|||||||
Some((
|
Some((
|
||||||
PathArguments::AngleBracketed(AngleBracketedGenericArguments {
|
PathArguments::AngleBracketed(AngleBracketedGenericArguments {
|
||||||
colon2_token: None,
|
colon2_token: None,
|
||||||
lt_token: Token),
|
lt_token: Token),
|
||||||
args,
|
args,
|
||||||
gt_token: Token),
|
gt_token: Token),
|
||||||
}),
|
}),
|
||||||
cursor,
|
cursor,
|
||||||
))
|
))
|
||||||
@ -191,7 +191,7 @@ impl HtmlComponent {
|
|||||||
let mut post_colons_cursor = cursor;
|
let mut post_colons_cursor = cursor;
|
||||||
if let Some(c) = Self::double_colon(post_colons_cursor) {
|
if let Some(c) = Self::double_colon(post_colons_cursor) {
|
||||||
if colons_optional {
|
if colons_optional {
|
||||||
leading_colon = Some(Token));
|
leading_colon = Some(Token));
|
||||||
}
|
}
|
||||||
post_colons_cursor = c;
|
post_colons_cursor = c;
|
||||||
} else if !colons_optional {
|
} else if !colons_optional {
|
||||||
|
|||||||
@ -60,7 +60,7 @@ impl Peek<'_, Self> for HtmlDashedName {
|
|||||||
if punct.as_char() == '-' {
|
if punct.as_char() == '-' {
|
||||||
let (ident, i_cursor) = p_cursor.ident()?;
|
let (ident, i_cursor) = p_cursor.ident()?;
|
||||||
cursor = i_cursor;
|
cursor = i_cursor;
|
||||||
extended.push((Token), ident));
|
extended.push((Token), ident));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -243,7 +243,7 @@ impl HtmlChildrenTree {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let vec_ident = Ident::new("__yew_v", Span::call_site());
|
let vec_ident = Ident::new("__yew_v", Span::mixed_site());
|
||||||
let add_children_streams = children.iter().map(|child| {
|
let add_children_streams = children.iter().map(|child| {
|
||||||
if let Some(node_iterator_stream) = child.to_node_iterator_stream() {
|
if let Some(node_iterator_stream) = child.to_node_iterator_stream() {
|
||||||
quote! {
|
quote! {
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
use yew::prelude::*;
|
#![no_implicit_prelude]
|
||||||
|
|
||||||
#[derive(Clone, Properties, PartialEq)]
|
#[derive(::yew::prelude::Properties, ::std::prelude::rust_2021::PartialEq,)]
|
||||||
struct Props {
|
struct Props {
|
||||||
a: usize,
|
a: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[function_component]
|
#[::yew::prelude::function_component]
|
||||||
fn Comp(props: &Props) -> Html {
|
fn Comp(props: &Props) -> ::yew::prelude::Html {
|
||||||
html! {
|
::yew::prelude::html! {
|
||||||
<p>
|
<p>
|
||||||
{ props.a }
|
{ props.a }
|
||||||
</p>
|
</p>
|
||||||
@ -15,7 +15,7 @@ fn Comp(props: &Props) -> Html {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _ = html! {
|
let _ = ::yew::prelude::html! {
|
||||||
<Comp a={0} />
|
<Comp a={0} />
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,25 +1,25 @@
|
|||||||
use yew::prelude::*;
|
#![no_implicit_prelude]
|
||||||
|
|
||||||
#[derive(Properties, Debug)]
|
#[derive(::yew::prelude::Properties, ::std::fmt::Debug)]
|
||||||
pub struct CompProps<A> {
|
pub struct CompProps<A> {
|
||||||
#[prop_or_default]
|
#[prop_or_default]
|
||||||
_phantom: std::marker::PhantomData<A>,
|
_phantom: ::std::marker::PhantomData<A>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A> PartialEq for CompProps<A> {
|
impl<A> ::std::cmp::PartialEq for CompProps<A> {
|
||||||
fn eq(&self, _rhs: &Self) -> bool {
|
fn eq(&self, _rhs: &Self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[function_component(Comp)]
|
#[::yew::prelude::function_component(Comp)]
|
||||||
pub fn comp<A = ()>(_props: &CompProps<A>) -> Html {
|
pub fn comp<A = ()>(_props: &CompProps<A>) -> ::yew::prelude::Html {
|
||||||
todo!()
|
::std::todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[function_component(App)]
|
#[::yew::prelude::function_component(App)]
|
||||||
pub fn app() -> Html {
|
pub fn app() -> ::yew::prelude::Html {
|
||||||
html! { <Comp /> } // No generics here.
|
::yew::prelude::html! { <Comp /> } // No generics here.
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use yew::prelude::*;
|
#![no_implicit_prelude]
|
||||||
|
|
||||||
#[hook]
|
#[::yew::functional::hook]
|
||||||
fn use_as_is<'a>(input: &'a ()) -> &'a () {
|
fn use_as_is<'a>(input: &'a ()) -> &'a () {
|
||||||
input
|
input
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
use yew::prelude::*;
|
#![no_implicit_prelude]
|
||||||
|
|
||||||
#[hook]
|
#[::yew::functional::hook]
|
||||||
pub fn use_some_macro_inner(val: &str) -> String {
|
pub fn use_some_macro_inner(val: &str) -> ::std::string::String {
|
||||||
use_state(|| val.to_owned()).to_string()
|
let state = ::yew::functional::use_state(|| ::std::borrow::ToOwned::to_owned(val));
|
||||||
|
::std::string::ToString::to_string(&*state)
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! use_some_macro {
|
macro_rules! use_some_macro {
|
||||||
@ -14,12 +15,12 @@ macro_rules! use_some_macro {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[function_component]
|
#[::yew::functional::function_component]
|
||||||
fn Comp() -> Html {
|
fn Comp() -> ::yew::Html {
|
||||||
let a = use_some_macro!();
|
let a = use_some_macro!();
|
||||||
let b = use_some_macro!("b");
|
let b = use_some_macro!("b");
|
||||||
|
|
||||||
html! {
|
::yew::html! {
|
||||||
<div>{a}{b}</div>
|
<div>{a}{b}</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,35 +1,35 @@
|
|||||||
use yew::prelude::*;
|
#![no_implicit_prelude]
|
||||||
|
|
||||||
fn compile_pass_lit() {
|
fn compile_pass_lit() {
|
||||||
html! { if true {} };
|
::yew::html! { if true {} };
|
||||||
html! { if true { <div/> } };
|
::yew::html! { if true { <div/> } };
|
||||||
html! { if true { <div/><div/> } };
|
::yew::html! { if true { <div/><div/> } };
|
||||||
html! { if true { <><div/><div/></> } };
|
::yew::html! { if true { <><div/><div/></> } };
|
||||||
html! { if true { { html! {} } } };
|
::yew::html! { if true { { ::yew::html! {} } } };
|
||||||
html! { if true { { { let _x = 42; html! {} } } } };
|
::yew::html! { if true { { { let _x = 42; ::yew::html! {} } } } };
|
||||||
html! { if true {} else {} };
|
::yew::html! { if true {} else {} };
|
||||||
html! { if true {} else if true {} };
|
::yew::html! { if true {} else if true {} };
|
||||||
html! { if true {} else if true {} else {} };
|
::yew::html! { if true {} else if true {} else {} };
|
||||||
html! { if let Some(text) = Some("text") { <span>{ text }</span> } };
|
::yew::html! { if let ::std::option::Option::Some(text) = ::std::option::Option::Some("text") { <span>{ text }</span> } };
|
||||||
html! { <><div/>if true {}<div/></> };
|
::yew::html! { <><div/>if true {}<div/></> };
|
||||||
html! { <div>if true {}</div> };
|
::yew::html! { <div>if true {}</div> };
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile_pass_expr() {
|
fn compile_pass_expr() {
|
||||||
let condition = true;
|
let condition = true;
|
||||||
|
|
||||||
html! { if condition {} };
|
::yew::html! { if condition {} };
|
||||||
html! { if condition { <div/> } };
|
::yew::html! { if condition { <div/> } };
|
||||||
html! { if condition { <div/><div/> } };
|
::yew::html! { if condition { <div/><div/> } };
|
||||||
html! { if condition { <><div/><div/></> } };
|
::yew::html! { if condition { <><div/><div/></> } };
|
||||||
html! { if condition { { html! {} } } };
|
::yew::html! { if condition { { ::yew::html! {} } } };
|
||||||
html! { if condition { { { let _x = 42; html! {} } } } };
|
::yew::html! { if condition { { { let _x = 42; ::yew::html! {} } } } };
|
||||||
html! { if condition {} else {} };
|
::yew::html! { if condition {} else {} };
|
||||||
html! { if condition {} else if condition {} };
|
::yew::html! { if condition {} else if condition {} };
|
||||||
html! { if condition {} else if condition {} else {} };
|
::yew::html! { if condition {} else if condition {} else {} };
|
||||||
html! { if let Some(text) = Some("text") { <span>{ text }</span> } };
|
::yew::html! { if let ::std::option::Option::Some(text) = ::std::option::Option::Some("text") { <span>{ text }</span> } };
|
||||||
html! { <><div/>if condition {}<div/></> };
|
::yew::html! { <><div/>if condition {}<div/></> };
|
||||||
html! { <div>if condition {}</div> };
|
::yew::html! { <div>if condition {}</div> };
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user