Skip to content

Commit

Permalink
ensure html_nested returns the inner type
Browse files Browse the repository at this point in the history
  • Loading branch information
ranile committed Oct 27, 2023
1 parent 04909dd commit 5493421
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
6 changes: 0 additions & 6 deletions packages/yew-macro/src/html_tree/html_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,42 +330,36 @@ impl ToTokens for HtmlElement {
let node = match &*name {
"input" => {
quote! {
::std::convert::Into::<::yew::virtual_dom::VNode>::into(
::yew::virtual_dom::VTag::__new_input(
#value,
#checked,
#node_ref,
#key,
#attributes,
#listeners,
),
)
}
}
"textarea" => {
quote! {
::std::convert::Into::<::yew::virtual_dom::VNode>::into(
::yew::virtual_dom::VTag::__new_textarea(
#value,
#node_ref,
#key,
#attributes,
#listeners,
),
)
}
}
_ => {
quote! {
::std::convert::Into::<::yew::virtual_dom::VNode>::into(
::yew::virtual_dom::VTag::__new_other(
::std::borrow::Cow::<'static, ::std::primitive::str>::Borrowed(#name),
#node_ref,
#key,
#attributes,
#listeners,
#children,
),
)
}
}
Expand Down
4 changes: 1 addition & 3 deletions packages/yew-macro/src/html_tree/html_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ impl ToTokens for HtmlList {
};

tokens.extend(quote_spanned! {spanned.span()=>
::yew::virtual_dom::VNode::VList(
::yew::virtual_dom::VList::with_children(#children, #key)
)
::yew::virtual_dom::VList::with_children(#children, #key)
});
}
}
Expand Down
7 changes: 3 additions & 4 deletions packages/yew-macro/src/html_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ impl ToTokens for HtmlTree {
fn to_tokens(&self, tokens: &mut TokenStream) {
lint::lint_all(self);
match self {
// this is consistent with VNode::default()
HtmlTree::Empty => tokens.extend(quote! {
::yew::virtual_dom::VNode::VList(::yew::virtual_dom::VList::new())
::yew::virtual_dom::VList::new()
}),
HtmlTree::Component(comp) => comp.to_tokens(tokens),
HtmlTree::Element(tag) => tag.to_tokens(tokens),
Expand Down Expand Up @@ -375,9 +376,7 @@ impl ToTokens for HtmlRootBraced {

tokens.extend(quote_spanned! {brace.span.span()=>
{
::yew::virtual_dom::VNode::VList(
::yew::virtual_dom::VList::with_children(#children, ::std::option::Option::None)
)
::yew::virtual_dom::VList::with_children(#children, ::std::option::Option::None)
}
});
}
Expand Down
32 changes: 32 additions & 0 deletions packages/yew/src/virtual_dom/vnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,35 @@ mod feat_ssr {
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::{function_component, html_nested, Html};

#[function_component]
fn Comp() -> Html {
todo!()
}

#[test]
fn html_nested_types() {
let _vlist: VList = html_nested! {
<>
<div>{"Hello"}</div>
<div>{"World"}</div>
</>
};
let _vlist2: VList = html_nested! {};
let _vtext: VText = html_nested!("");
let _vcomp: VChild<Comp> = html_nested! { <Comp /> };
let _vtag: VTag = html_nested! { <div></div> };

let _vif: VList = html_nested! {
if true {
<div>
</div>
}
};
}
}

0 comments on commit 5493421

Please sign in to comment.