Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
its-the-shrimp committed Oct 13, 2023
1 parent 0c43713 commit 6dbdf9a
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions packages/yew-macro/src/html_tree/html_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use quote::{quote, quote_spanned, ToTokens};
use syn::buffer::Cursor;
use syn::parse::{Parse, ParseStream, Result};
use syn::spanned::Spanned;
use syn::{Lit, Block, Stmt};
use syn::{Block, Lit, Stmt};

use super::ToNodeIterator;
use crate::stringify::Stringify;
Expand Down Expand Up @@ -49,14 +49,16 @@ impl ToTokens for HtmlNode {
let sr = lit.stringify();
quote_spanned! {lit.span()=> ::yew::virtual_dom::VText::new(#sr) }
}
HtmlNode::Expression(stmts) => if let [expr] = &stmts[..] {
quote! {#expr}
} else {
let mut block = TokenStream::new();
for stmt in stmts.iter() {
stmt.to_tokens(&mut block)
HtmlNode::Expression(stmts) => {
if let [expr] = &stmts[..] {
quote! {#expr}
} else {
let mut block = TokenStream::new();
for stmt in stmts.iter() {
stmt.to_tokens(&mut block)
}
quote_spanned! {block.span()=> {#block}}
}
quote_spanned! {block.span()=> {#block}}
}
});
}
Expand All @@ -66,19 +68,23 @@ impl ToNodeIterator for HtmlNode {
fn to_node_iterator_stream(&self) -> Option<TokenStream> {
match self {
HtmlNode::Literal(_) => None,
HtmlNode::Expression(stmts) => if let [expr] = &stmts[..] {
Some(quote_spanned! {expr.span().resolved_at(Span::call_site())=>
::std::convert::Into::<::yew::utils::NodeSeq<_, _>>::into(#expr)
})
} else {
let mut block = TokenStream::new();
for stmt in stmts.iter() {
stmt.to_tokens(&mut block)
HtmlNode::Expression(stmts) => {
if let [expr] = &stmts[..] {
Some(quote_spanned! {expr.span().resolved_at(Span::call_site())=>
::std::convert::Into::<::yew::utils::NodeSeq<_, _>>::into(#expr)
})
} else {
let mut block = TokenStream::new();
for stmt in stmts.iter() {
stmt.to_tokens(&mut block)
}
// NodeSeq turns both Into<T> and Vec<Into<T>> into IntoIterator<Item = T>
Some(
quote_spanned! {block.span().resolved_at(Span::call_site())=>
::std::convert::Into::<::yew::utils::NodeSeq<_, _>>::into({#block})
},
)
}
// NodeSeq turns both Into<T> and Vec<Into<T>> into IntoIterator<Item = T>
Some(quote_spanned! {block.span().resolved_at(Span::call_site())=>
::std::convert::Into::<::yew::utils::NodeSeq<_, _>>::into({#block})
})
}
}
}
Expand Down

0 comments on commit 6dbdf9a

Please sign in to comment.