diff --git a/CHANGES.md b/CHANGES.md index de974d15..26117b81 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,10 @@ * Hush excessive logging when no Content-Type or cookie provided +### Fixed + +* Docstrings and other attributes in `component!` macro + ## 0.6.0 - 2024-08-02 ### Added diff --git a/crates/vertigo-macro/src/component.rs b/crates/vertigo-macro/src/component.rs index 1b27400a..07a09403 100644 --- a/crates/vertigo-macro/src/component.rs +++ b/crates/vertigo-macro/src/component.rs @@ -1,6 +1,6 @@ use proc_macro::{Span, TokenStream}; use quote::{quote, ToTokens}; -use syn::Visibility; +use syn::{FnArg, Visibility}; pub(crate) fn component_inner(input: TokenStream) -> TokenStream { let ast = syn::parse_macro_input!(input as syn::ItemFn); @@ -25,10 +25,16 @@ pub(crate) fn component_inner(input: TokenStream) -> TokenStream { let mut struct_fields = Vec::new(); - for field in ast.sig.inputs.iter() { - struct_fields.push(quote! { - pub #field - }) + for field in ast.sig.inputs.clone().into_iter() { + match field { + FnArg::Receiver(_) => unreachable!(), + FnArg::Typed(mut pat_type) => { + let attrs = pat_type.attrs.drain(..); + struct_fields.push(quote! { + #(#attrs)* pub #pat_type + }) + } + } } let body = ast.block; diff --git a/crates/vertigo/src/tests/dom/component.rs b/crates/vertigo/src/tests/dom/component.rs index 0e4b4751..79b297a4 100644 --- a/crates/vertigo/src/tests/dom/component.rs +++ b/crates/vertigo/src/tests/dom/component.rs @@ -1,5 +1,5 @@ #[test] -fn test_lifetimes() { +fn test_if_lifetimes_allowed() { use crate::{self as vertigo, component, dom, DomNode}; #[component] @@ -72,3 +72,24 @@ fn test_namespaces() { _ => panic!("Expected DomNode::Node"), } } + +#[test] +fn test_if_docstrings_allowed() { + use crate::{self as vertigo, component, dom, DomNode}; + + #[component] + fn Hello<'a>( + /// Name of the person you want to greet + name: &'a str, + ) { + dom! { + "Hello " {name} + } + } + + let ret = dom! { +