Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properties with into and default attribute calls into() in proc macro #2407

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions leptos_macro/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,12 @@ impl TypedBuilderOpts {
impl TypedBuilderOpts {
fn to_serde_tokens(&self) -> TokenStream {
let default = if let Some(v) = &self.default_with_value {
let v = v.to_token_stream().to_string();
quote! { default=#v, }
let mut v = v.to_token_stream();
if self.into {
v.append_all(quote!{.into()} );
}
let v = v.to_string();
quote! { default_code=#v, }
} else if self.default {
quote! { default, }
} else {
Expand All @@ -863,7 +867,11 @@ impl TypedBuilderOpts {
impl ToTokens for TypedBuilderOpts {
fn to_tokens(&self, tokens: &mut TokenStream) {
let default = if let Some(v) = &self.default_with_value {
let v = v.to_token_stream().to_string();
let mut v = v.to_token_stream();
if self.into {
v.append_all(quote!{.into()} );
}
let v = v.to_string();
quote! { default_code=#v, }
} else if self.default {
quote! { default, }
Expand Down
6 changes: 5 additions & 1 deletion leptos_macro/src/slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ impl TypedBuilderOpts {
impl ToTokens for TypedBuilderOpts {
fn to_tokens(&self, tokens: &mut TokenStream) {
let default = if let Some(v) = &self.default_with_value {
let v = v.to_token_stream().to_string();
let mut v = v.to_token_stream();
if self.into {
v.append_all(quote!{.into()} );
}
let v = v.to_string();
quote! { default_code=#v, }
} else if self.default {
quote! { default, }
Expand Down
6 changes: 6 additions & 0 deletions leptos_macro/tests/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ fn Component(
#[prop(strip_option)] strip_option: Option<u8>,
#[prop(default = NonZeroUsize::new(10).unwrap())] default: NonZeroUsize,
#[prop(into)] into: String,
#[prop(into, default = "Default value")] into_default: String,
#[prop(into, default = NonZeroUsize::new(11).unwrap())] into_default_expr: NonZeroUsize,
) -> impl IntoView {
_ = optional;
_ = optional_no_strip;
_ = strip_option;
_ = default;
_ = into;
_ = into_default;
_ = into_default_expr;
}

#[test]
Expand All @@ -24,4 +28,6 @@ fn component() {
assert_eq!(cp.strip_option, Some(9));
assert_eq!(cp.default, NonZeroUsize::new(10).unwrap());
assert_eq!(cp.into, "");
assert_eq!(cp.into_default, "Default value");
assert_eq!(cp.into_default_expr, NonZeroUsize::new(11).unwrap());
}
Loading