Skip to content

Commit

Permalink
Attach all attributes except doc comments to function instead of struct
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechu10 committed Nov 30, 2021
1 parent ce83243 commit 209b1a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/sycamore-macro/src/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,23 @@ pub fn component_impl(
arg,
mut generics,
vis,
attrs,
mut attrs,
name,
return_type,
} = component;

let mut doc_attrs = Vec::new();
let mut i = 0;
while i < attrs.len() {
if attrs[i].path.is_ident("doc") {
// Attribute is a doc attribute. Remove from attrs and add to doc_attrs.
let at = attrs.remove(i);
doc_attrs.push(at);
} else {
i += 1;
}
}

let prop_ty = match &arg {
FnArg::Receiver(_) => unreachable!(),
FnArg::Typed(pat_ty) => &pat_ty.ty,
Expand Down Expand Up @@ -226,7 +238,7 @@ pub fn component_impl(
}

let quoted = quote! {
#(#attrs)*
#(#doc_attrs)*
#vis struct #component_name#generics {
#[doc(hidden)]
_marker: ::std::marker::PhantomData<(#phantom_generics)>,
Expand All @@ -239,6 +251,7 @@ pub fn component_impl(
const NAME: &'static ::std::primitive::str = #component_name_str;
type Props = #prop_ty;

#(#attrs)*
fn create_component(#arg) -> #return_type{
#block
}
Expand Down
1 change: 1 addition & 0 deletions packages/sycamore/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ where
/// # }
/// ```
#[component(ContextProvider<G>)]
#[cfg_attr(debug_assertions, track_caller)]
pub fn context_provider<T, F>(props: ContextProviderProps<T, F, G>) -> View<G>
where
T: 'static,
Expand Down

0 comments on commit 209b1a1

Please sign in to comment.