@@ -24,7 +24,7 @@ mod utils;
2424#[ allow( clippy:: wildcard_imports) ]
2525use utils:: * ;
2626
27- /// Converts the children into a `leptos::Fragment::lazy ()` token stream.
27+ /// Converts the children into a `View::new ()` token stream.
2828///
2929/// Example:
3030/// ```ignore
@@ -41,9 +41,7 @@ use utils::*;
4141/// {"b"},
4242/// ))
4343/// ```
44-
45- // used in the root or for component children
46- pub fn children_fragment_tokens < ' a > (
44+ pub fn root_children_tokens < ' a > (
4745 children : impl Iterator < Item = & ' a NodeChild > ,
4846 span : Span ,
4947) -> TokenStream {
@@ -54,6 +52,25 @@ pub fn children_fragment_tokens<'a>(
5452 }
5553}
5654
55+ // used for component children
56+ pub fn children_fragment_tokens < ' a > (
57+ children : impl Iterator < Item = & ' a NodeChild > ,
58+ span : Span ,
59+ ) -> TokenStream {
60+ let children = children. collect :: < Vec < _ > > ( ) ;
61+ let has_multiple_children = children. len ( ) > 1 ;
62+
63+ if has_multiple_children {
64+ quote_spanned ! { span=>
65+ ( #( #children, ) * )
66+ }
67+ } else {
68+ quote_spanned ! { span=>
69+ #( #children ) *
70+ }
71+ }
72+ }
73+
5774/// Converts an xml (like html, svg or math) element to tokens.
5875///
5976/// Returns `None` if the element is not an xml element (custom component).
@@ -291,23 +308,22 @@ pub fn component_to_tokens<const IS_SLOT: bool>(element: &Element) -> Option<Tok
291308 path. span( ) => :: leptos:: component:: component_props_builder( & #path)
292309 } ;
293310
311+ let directive_paths = ( !directive_paths. is_empty ( ) ) . then ( || {
312+ quote ! {
313+ . add_any_attr( ( #( #directive_paths, ) * ) )
314+ }
315+ } ) ;
316+
294317 Some ( quote ! {
295- // the .build() returns `!` if not all props are present.
296- // this causes unreachable code warning in ::leptos::component_view
297- #[ allow( unreachable_code) ]
298- :: leptos:: prelude:: View :: new(
299- :: leptos:: component:: component_view(
300- & #path,
301- #component_props_builder
302- #attrs
303- #children
304- #slot_children
305- #build
306- )
307- . add_any_attr( (
308- #( #directive_paths, ) *
309- ) )
318+ :: leptos:: component:: component_view(
319+ & #path,
320+ #component_props_builder
321+ #attrs
322+ #children
323+ #slot_children
324+ #build
310325 )
326+ #directive_paths
311327 } )
312328 }
313329}
0 commit comments