|
@@ -1,10 +1,11 @@
|
|
|
-use dioxus_rsx::{BodyNode, ElementAttr, ElementAttrNamed};
|
|
|
+use dioxus_rsx::{BodyNode, ElementAttr, ElementAttrNamed, ForLoop};
|
|
|
use proc_macro2::{LineColumn, Span};
|
|
|
+use quote::ToTokens;
|
|
|
use std::{
|
|
|
collections::{HashMap, VecDeque},
|
|
|
fmt::{Result, Write},
|
|
|
};
|
|
|
-use syn::{spanned::Spanned, Expr};
|
|
|
+use syn::{spanned::Spanned, Expr, ExprIf};
|
|
|
|
|
|
use crate::buffer::Buffer;
|
|
|
|
|
@@ -37,8 +38,9 @@ impl Writer {
|
|
|
BodyNode::Element(el) => self.write_element(el),
|
|
|
BodyNode::Component(component) => self.write_component(component),
|
|
|
BodyNode::Text(text) => self.out.write_text(text),
|
|
|
- BodyNode::RawExpr(exp) => self.write_raw_expr(exp),
|
|
|
- _ => Ok(()),
|
|
|
+ BodyNode::RawExpr(exp) => self.write_raw_expr(exp.span()),
|
|
|
+ BodyNode::ForLoop(forloop) => self.write_for_loop(forloop),
|
|
|
+ BodyNode::IfChain(ifchain) => self.write_if_chain(ifchain),
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -176,6 +178,31 @@ impl Writer {
|
|
|
.or_insert_with(|| prettyplease::unparse_expr(expr))
|
|
|
.as_str()
|
|
|
}
|
|
|
+
|
|
|
+ fn write_for_loop(&mut self, forloop: &ForLoop) -> std::fmt::Result {
|
|
|
+ write!(
|
|
|
+ self.out,
|
|
|
+ "for {} in {} {{",
|
|
|
+ forloop.pat.clone().into_token_stream().to_string(),
|
|
|
+ prettyplease::unparse_expr(&forloop.expr)
|
|
|
+ )?;
|
|
|
+
|
|
|
+ if forloop.body.is_empty() {
|
|
|
+ write!(self.out, "}}")?;
|
|
|
+ return Ok(());
|
|
|
+ }
|
|
|
+
|
|
|
+ self.write_body_indented(&forloop.body)?;
|
|
|
+
|
|
|
+ self.out.tabbed_line()?;
|
|
|
+ write!(self.out, "}}")?;
|
|
|
+
|
|
|
+ Ok(())
|
|
|
+ }
|
|
|
+
|
|
|
+ fn write_if_chain(&mut self, ifchain: &ExprIf) -> std::fmt::Result {
|
|
|
+ self.write_raw_expr(ifchain.span())
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
trait SpanLength {
|