diff --git a/packages/yew-macro/src/props/prop.rs b/packages/yew-macro/src/props/prop.rs index 4b9240a02..6fb4d7522 100644 --- a/packages/yew-macro/src/props/prop.rs +++ b/packages/yew-macro/src/props/prop.rs @@ -120,6 +120,15 @@ fn strip_braces(block: ExprBlock) -> syn::Result { let stmt = stmts.remove(0); match stmt { Stmt::Expr(expr) => Ok(expr), + // See issue #2267, we want to parse macro invocations as expressions + Stmt::Item(syn::Item::Macro(mac)) + if mac.ident.is_none() && mac.semi_token.is_none() => + { + Ok(Expr::Macro(syn::ExprMacro { + attrs: mac.attrs, + mac: mac.mac, + })) + } Stmt::Semi(_expr, semi) => Err(syn::Error::new_spanned( semi, "only an expression may be assigned as a property. Consider removing this \ diff --git a/packages/yew-macro/tests/html_macro/component-fail.rs b/packages/yew-macro/tests/html_macro/component-fail.rs index 12004c71a..e5c9e9985 100644 --- a/packages/yew-macro/tests/html_macro/component-fail.rs +++ b/packages/yew-macro/tests/html_macro/component-fail.rs @@ -118,7 +118,18 @@ fn compile_fail() { html! { }; html! { }; html! { }; +} +#[derive(Clone, Properties, PartialEq)] +pub struct HtmlInPropsProperties { + pub header: ::yew::Html, +} +#[function_component] +fn HtmlInProps(props: &HtmlInPropsProperties) -> Html { let _ = (); unimplemented!() } + +fn not_expressions() { + html! { }; + html! { }; } fn main() {} diff --git a/packages/yew-macro/tests/html_macro/component-fail.stderr b/packages/yew-macro/tests/html_macro/component-fail.stderr index 5374e76ba..c09de0577 100644 --- a/packages/yew-macro/tests/html_macro/component-fail.stderr +++ b/packages/yew-macro/tests/html_macro/component-fail.stderr @@ -255,6 +255,18 @@ error: missing label for property value. If trying to use the shorthand property 120 | html! { }; | ^^^^^^^^^^^^^^ +error: only an expression may be assigned as a property + --> tests/html_macro/component-fail.rs:131:34 + | +131 | html! { }; + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: only an expression may be assigned as a property. Consider removing this semicolon + --> tests/html_macro/component-fail.rs:132:61 + | +132 | html! { }; + | ^ + error[E0425]: cannot find value `blah` in this scope --> tests/html_macro/component-fail.rs:68:22 | diff --git a/packages/yew-macro/tests/html_macro/component-pass.rs b/packages/yew-macro/tests/html_macro/component-pass.rs index 3d4323680..707c08f5f 100644 --- a/packages/yew-macro/tests/html_macro/component-pass.rs +++ b/packages/yew-macro/tests/html_macro/component-pass.rs @@ -43,6 +43,8 @@ pub struct ContainerProperties { pub int: ::std::primitive::i32, #[prop_or_default] pub children: ::yew::Children, + #[prop_or_default] + pub header: ::yew::Html, } pub struct Container; @@ -273,6 +275,9 @@ fn compile_pass() { + + }} /> }; diff --git a/website/docs/advanced-topics/children.mdx b/website/docs/advanced-topics/children.mdx index c48ddabf9..a05dbf4b5 100644 --- a/website/docs/advanced-topics/children.mdx +++ b/website/docs/advanced-topics/children.mdx @@ -241,9 +241,9 @@ pub fn render_page(with_sidebar: bool) -> Html { if with_sidebar { // Page with sidebar html! { - - }}} /> + }} /> } } else { // Page without sidebar