mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-26 22:20:19 +00:00
fix tests around children elements
This commit is contained in:
parent
b8061d6d14
commit
8a77d2560e
4 changed files with 26 additions and 8 deletions
|
@ -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 } }
|
||||
}
|
||||
|
|
|
@ -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} }
|
||||
/// })
|
||||
/// }
|
||||
/// ```
|
||||
|
|
|
@ -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()?);
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue