Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
::yew::virtual_dom::AttrValue::Static(#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(::std::rc::Rc::new(
::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 as ::std::default::Default>::default()
::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(::std::rc::Rc::new(
::yew::virtual_dom::VList::with_children(#children, ::std::option::Option::None)
))
::yew::virtual_dom::VList::with_children(#children, ::std::option::Option::None)
}
});
}
Expand Down
14 changes: 8 additions & 6 deletions packages/yew-macro/tests/html_macro/component-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -710,21 +710,23 @@ note: required by a bound in `ChildContainerPropertiesBuilder::children`
| -------- required by a bound in this
= note: this error originates in the macro `html` which comes from the expansion of the derive macro `Properties` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `VChild<Child>: From<VNode>` is not satisfied
error[E0277]: the trait bound `VChild<Child>: From<yew::virtual_dom::VList>` is not satisfied
--> tests/html_macro/component-fail.rs:118:29
|
118 | html! { <ChildContainer><></></ChildContainer> };
| ^ the trait `From<VNode>` is not implemented for `VChild<Child>`
| ^ the trait `From<yew::virtual_dom::VList>` is not implemented for `VChild<Child>`
|
= note: required because of the requirements on the impl of `Into<VChild<Child>>` for `VNode`
= note: required because of the requirements on the impl of `Into<VChild<Child>>` for `yew::virtual_dom::VList`

error[E0277]: the trait bound `VNode: IntoPropValue<ChildrenRenderer<VChild<Child>>>` is not satisfied
error[E0277]: the trait bound `yew::virtual_dom::VTag: IntoPropValue<ChildrenRenderer<VChild<Child>>>` is not satisfied
--> tests/html_macro/component-fail.rs:119:14
|
119 | html! { <ChildContainer><other /></ChildContainer> };
| ^^^^^^^^^^^^^^ the trait `IntoPropValue<ChildrenRenderer<VChild<Child>>>` is not implemented for `VNode`
| ^^^^^^^^^^^^^^ the trait `IntoPropValue<ChildrenRenderer<VChild<Child>>>` is not implemented for `yew::virtual_dom::VTag`
|
= help: the trait `IntoPropValue<ChildrenRenderer<VNode>>` is implemented for `VNode`
= help: the following other types implement trait `IntoPropValue<T>`:
<yew::virtual_dom::VTag as IntoPropValue<ChildrenRenderer<VNode>>>
<yew::virtual_dom::VTag as IntoPropValue<VNode>>
note: required by a bound in `ChildContainerPropertiesBuilder::children`
--> tests/html_macro/component-fail.rs:24:17
|
Expand Down
16 changes: 15 additions & 1 deletion packages/yew/src/html/conversion/into_prop_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub use implicit_clone::ImplicitClone;

use crate::callback::Callback;
use crate::html::{BaseComponent, ChildrenRenderer, Component, NodeRef, Scope};
use crate::virtual_dom::{AttrValue, VChild, VList, VNode, VText};
use crate::virtual_dom::{AttrValue, VChild, VList, VNode, VTag, VText};

impl ImplicitClone for NodeRef {}
impl<Comp: Component> ImplicitClone for Scope<Comp> {}
Expand Down Expand Up @@ -153,6 +153,13 @@ impl IntoPropValue<VNode> for VText {
}
}

impl IntoPropValue<VNode> for VTag {
#[inline]
fn into_prop_value(self) -> VNode {
VNode::VTag(Rc::new(self))
}
}

impl IntoPropValue<VNode> for () {
#[inline]
fn into_prop_value(self) -> VNode {
Expand Down Expand Up @@ -181,6 +188,13 @@ impl IntoPropValue<ChildrenRenderer<VNode>> for VText {
}
}

impl IntoPropValue<ChildrenRenderer<VNode>> for VTag {
#[inline]
fn into_prop_value(self) -> ChildrenRenderer<VNode> {
ChildrenRenderer::new(vec![self.into()])
}
}

impl IntoPropValue<VList> for ChildrenRenderer<VNode> {
#[inline]
fn into_prop_value(self) -> VList {
Expand Down
34 changes: 34 additions & 0 deletions packages/yew/src/virtual_dom/vnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,37 @@ 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 _vtag: VTag = html_nested! { <textarea /> };
let _vtag: VTag = html_nested! { <input /> };

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