Skip to content

Commit

Permalink
Forward attributes on function parameters to generated prop struct
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechu10 committed Nov 3, 2024
1 parent 47ca5f1 commit 96e97d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions packages/sycamore-macro/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,19 +280,18 @@ fn inline_props_impl(item: &mut ItemFn, attrs: Punctuated<Meta, Token![,]>) -> R
let props = inputs.clone().into_iter().collect::<Vec<_>>();
let generics: &mut Generics = &mut item.sig.generics;
let mut fields = Vec::new();
inputs.iter().for_each(|arg| match arg {
inputs.into_iter().for_each(|arg| match arg {
FnArg::Receiver(_) => {
unreachable!("receiver cannot be a prop")
}
FnArg::Typed(pat_type) => {
let pat = &*pat_type.pat;
let ty = &*pat_type.ty;
match pat {
match *pat_type.pat {
Pat::Ident(ident_pat) => super::inline_props::push_field(
&mut fields,
generics,
pat_type.attrs,
ident_pat.clone().ident,
ty.clone(),
*pat_type.ty,
),
_ => {
unreachable!("unexpected pattern!")
Expand Down
4 changes: 2 additions & 2 deletions packages/sycamore-macro/src/inline_props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ pub fn add_generic(generics: &mut Generics, impl_type: TypeImplTrait) -> Type {
})
}

pub fn push_field(fields: &mut Vec<Field>, generics: &mut Generics, ident: Ident, ty: Type) {
pub fn push_field(fields: &mut Vec<Field>, generics: &mut Generics, attrs: Vec<Attributes>, ident: Ident, ty: Type) {
let ty = resolve_type(generics, ty);

fields.push(Field {
attrs: Vec::new(),
attrs,
vis: Visibility::Public(Token![pub](Span::call_site())),
mutability: syn::FieldMutability::None,
ident: Some(ident),
Expand Down

0 comments on commit 96e97d4

Please sign in to comment.