fix tests around children elements

This commit is contained in:
Jonathan Kelley 2024-01-10 23:42:36 -08:00
parent b8061d6d14
commit 8a77d2560e
No known key found for this signature in database
GPG key ID: 1FBB50F7EB0A08BE
4 changed files with 26 additions and 8 deletions

View file

@ -11,8 +11,11 @@ fn app(cx: Scope) -> Element {
let class = "class";
let id = "id";
// todo: i'd like it for children to be inferred
let children = render! { "Child" };
render! {
div { class, id }
div { class, id, {children} }
Component { a, b, c }
Component { a, ..ComponentProps { a: 1, b: 2, c: 3 } }
}

View file

@ -78,7 +78,7 @@ use std::{
/// #[component]
/// fn Title<'a>(cx: Scope<'a>, children: Element<'a>) -> Element {
/// cx.render(rsx! {
/// div { id: "title", children }
/// div { id: "title", {children} }
/// })
/// }
/// ```

View file

@ -55,14 +55,23 @@ impl Parse for Component {
manual_props = Some(content.parse()?);
} else if
// Named fields
(content.peek(Ident) && content.peek2(Token![:]) && !content.peek3(Token![:]))
content.peek(Ident) && content.peek2(Token![:]) && !content.peek3(Token![:]) {
fields.push(content.parse()?);
} else if
// shorthand struct initialization
// Not a div {}, mod::Component {}, or web-component {}
|| (content.peek(Ident)
content.peek(Ident)
&& !content.peek2(Brace)
&& !content.peek2(Token![:])
&& !content.peek2(Token![-]))
&& !content.peek2(Token![-])
{
let name = content.fork().parse::<Ident>().unwrap().to_string();
// If the shorthand field is children, these are actually children!
if name == "children" {
panic!("children must be wrapped in braces");
};
fields.push(content.parse()?);
} else {
children.push(content.parse()?);

View file

@ -137,6 +137,12 @@ impl Parse for Element {
{
let name = content.parse::<Ident>()?;
let name_ = name.clone();
// If the shorthand field is children, these are actually children!
if name == "children" {
panic!("children must be wrapped in braces");
};
let value = ElementAttrValue::Shorthand(name.clone());
attributes.push(attribute::AttributeType::Named(ElementAttrNamed {
el_name: el_name.clone(),