Skip to content

Commit 5493421

Browse files
committed
ensure html_nested returns the inner type
1 parent 04909dd commit 5493421

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

packages/yew-macro/src/html_tree/html_element.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,42 +330,36 @@ impl ToTokens for HtmlElement {
330330
let node = match &*name {
331331
"input" => {
332332
quote! {
333-
::std::convert::Into::<::yew::virtual_dom::VNode>::into(
334333
::yew::virtual_dom::VTag::__new_input(
335334
#value,
336335
#checked,
337336
#node_ref,
338337
#key,
339338
#attributes,
340339
#listeners,
341-
),
342340
)
343341
}
344342
}
345343
"textarea" => {
346344
quote! {
347-
::std::convert::Into::<::yew::virtual_dom::VNode>::into(
348345
::yew::virtual_dom::VTag::__new_textarea(
349346
#value,
350347
#node_ref,
351348
#key,
352349
#attributes,
353350
#listeners,
354-
),
355351
)
356352
}
357353
}
358354
_ => {
359355
quote! {
360-
::std::convert::Into::<::yew::virtual_dom::VNode>::into(
361356
::yew::virtual_dom::VTag::__new_other(
362357
::std::borrow::Cow::<'static, ::std::primitive::str>::Borrowed(#name),
363358
#node_ref,
364359
#key,
365360
#attributes,
366361
#listeners,
367362
#children,
368-
),
369363
)
370364
}
371365
}

packages/yew-macro/src/html_tree/html_list.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ impl ToTokens for HtmlList {
7878
};
7979

8080
tokens.extend(quote_spanned! {spanned.span()=>
81-
::yew::virtual_dom::VNode::VList(
82-
::yew::virtual_dom::VList::with_children(#children, #key)
83-
)
81+
::yew::virtual_dom::VList::with_children(#children, #key)
8482
});
8583
}
8684
}

packages/yew-macro/src/html_tree/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ impl ToTokens for HtmlTree {
122122
fn to_tokens(&self, tokens: &mut TokenStream) {
123123
lint::lint_all(self);
124124
match self {
125+
// this is consistent with VNode::default()
125126
HtmlTree::Empty => tokens.extend(quote! {
126-
::yew::virtual_dom::VNode::VList(::yew::virtual_dom::VList::new())
127+
::yew::virtual_dom::VList::new()
127128
}),
128129
HtmlTree::Component(comp) => comp.to_tokens(tokens),
129130
HtmlTree::Element(tag) => tag.to_tokens(tokens),
@@ -375,9 +376,7 @@ impl ToTokens for HtmlRootBraced {
375376

376377
tokens.extend(quote_spanned! {brace.span.span()=>
377378
{
378-
::yew::virtual_dom::VNode::VList(
379-
::yew::virtual_dom::VList::with_children(#children, ::std::option::Option::None)
380-
)
379+
::yew::virtual_dom::VList::with_children(#children, ::std::option::Option::None)
381380
}
382381
});
383382
}

packages/yew/src/virtual_dom/vnode.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,35 @@ mod feat_ssr {
257257
}
258258
}
259259
}
260+
261+
#[cfg(test)]
262+
mod tests {
263+
use super::*;
264+
use crate::{function_component, html_nested, Html};
265+
266+
#[function_component]
267+
fn Comp() -> Html {
268+
todo!()
269+
}
270+
271+
#[test]
272+
fn html_nested_types() {
273+
let _vlist: VList = html_nested! {
274+
<>
275+
<div>{"Hello"}</div>
276+
<div>{"World"}</div>
277+
</>
278+
};
279+
let _vlist2: VList = html_nested! {};
280+
let _vtext: VText = html_nested!("");
281+
let _vcomp: VChild<Comp> = html_nested! { <Comp /> };
282+
let _vtag: VTag = html_nested! { <div></div> };
283+
284+
let _vif: VList = html_nested! {
285+
if true {
286+
<div>
287+
</div>
288+
}
289+
};
290+
}
291+
}

0 commit comments

Comments
 (0)