fix tests around children elements

This commit is contained in:
Jonathan Kelley committed 2024-01-10 23:42:36 -08:00
1 parent b8061d6d14
commit 8a77d2560e
4 files changed
+26 -8

No files matched your search

+4 -1
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 } }
}
+1 -1
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} }
/// })
/// }
/// ```
+15 -6
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.peek2(Brace)
&& !content.peek2(Token![:])
&& !content.peek2(Token![-]))
// Not a div {}, mod::Component {}, or web-component {}
content.peek(Ident)
&& !content.peek2(Brace)
&& !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()?);
+6
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(),