|
@@ -1,13 +1,10 @@
|
|
use crate::parser::{HtmlParser, NodesToPush};
|
|
use crate::parser::{HtmlParser, NodesToPush};
|
|
use quote::quote;
|
|
use quote::quote;
|
|
-use syn::{Stmt, Expr, ExprIf};
|
|
|
|
|
|
+use syn::{Expr, ExprIf, Stmt};
|
|
|
|
|
|
impl HtmlParser {
|
|
impl HtmlParser {
|
|
/// Parse an incoming syn::Stmt node inside a block
|
|
/// Parse an incoming syn::Stmt node inside a block
|
|
- pub(crate) fn parse_statement(
|
|
|
|
- &mut self,
|
|
|
|
- stmt: &Stmt,
|
|
|
|
- ) {
|
|
|
|
|
|
+ pub(crate) fn parse_statement(&mut self, stmt: &Stmt) {
|
|
// Here we handle a block being a descendant within some html! call.
|
|
// Here we handle a block being a descendant within some html! call.
|
|
//
|
|
//
|
|
// The descendant should implement Into<IterableNodes>
|
|
// The descendant should implement Into<IterableNodes>
|
|
@@ -16,7 +13,7 @@ impl HtmlParser {
|
|
match stmt {
|
|
match stmt {
|
|
Stmt::Expr(expr) => {
|
|
Stmt::Expr(expr) => {
|
|
self.parse_expr(stmt, expr);
|
|
self.parse_expr(stmt, expr);
|
|
- },
|
|
|
|
|
|
+ }
|
|
_ => {
|
|
_ => {
|
|
self.push_iterable_nodes(NodesToPush::Stmt(stmt));
|
|
self.push_iterable_nodes(NodesToPush::Stmt(stmt));
|
|
}
|
|
}
|
|
@@ -24,15 +21,11 @@ impl HtmlParser {
|
|
}
|
|
}
|
|
|
|
|
|
/// Parse an incoming syn::Expr node inside a block
|
|
/// Parse an incoming syn::Expr node inside a block
|
|
- pub(crate) fn parse_expr(
|
|
|
|
- &mut self,
|
|
|
|
- stmt: &Stmt,
|
|
|
|
- expr: &Expr
|
|
|
|
- ) {
|
|
|
|
|
|
+ pub(crate) fn parse_expr(&mut self, stmt: &Stmt, expr: &Expr) {
|
|
match expr {
|
|
match expr {
|
|
Expr::If(expr_if) => {
|
|
Expr::If(expr_if) => {
|
|
self.expand_if(stmt, expr_if);
|
|
self.expand_if(stmt, expr_if);
|
|
- },
|
|
|
|
|
|
+ }
|
|
_ => {
|
|
_ => {
|
|
self.push_iterable_nodes(NodesToPush::Stmt(stmt));
|
|
self.push_iterable_nodes(NodesToPush::Stmt(stmt));
|
|
}
|
|
}
|
|
@@ -42,9 +35,9 @@ impl HtmlParser {
|
|
/// Expand an incoming Expr::If block
|
|
/// Expand an incoming Expr::If block
|
|
/// This enables us to use JSX-style conditions inside of blocks such as
|
|
/// This enables us to use JSX-style conditions inside of blocks such as
|
|
/// the following example.
|
|
/// the following example.
|
|
- ///
|
|
|
|
|
|
+ ///
|
|
/// # Examples
|
|
/// # Examples
|
|
- ///
|
|
|
|
|
|
+ ///
|
|
/// ```rust,ignore
|
|
/// ```rust,ignore
|
|
/// html! {
|
|
/// html! {
|
|
/// <div>
|
|
/// <div>
|
|
@@ -54,16 +47,12 @@ impl HtmlParser {
|
|
/// </div>
|
|
/// </div>
|
|
/// }
|
|
/// }
|
|
/// ```
|
|
/// ```
|
|
- ///
|
|
|
|
|
|
+ ///
|
|
/// Traditionally this would be possible as an if statement in rust is an
|
|
/// Traditionally this would be possible as an if statement in rust is an
|
|
/// expression, so the then, and the else block have to return matching types.
|
|
/// expression, so the then, and the else block have to return matching types.
|
|
/// Here we identify whether the block is missing the else and fill it in with
|
|
/// Here we identify whether the block is missing the else and fill it in with
|
|
/// a blank VirtualNode::text("")
|
|
/// a blank VirtualNode::text("")
|
|
- pub(crate) fn expand_if(
|
|
|
|
- &mut self,
|
|
|
|
- stmt: &Stmt,
|
|
|
|
- expr_if: &ExprIf
|
|
|
|
- ) {
|
|
|
|
|
|
+ pub(crate) fn expand_if(&mut self, stmt: &Stmt, expr_if: &ExprIf) {
|
|
// Has else branch, we can parse the expression as normal.
|
|
// Has else branch, we can parse the expression as normal.
|
|
if let Some(_else_branch) = &expr_if.else_branch {
|
|
if let Some(_else_branch) = &expr_if.else_branch {
|
|
self.push_iterable_nodes(NodesToPush::Stmt(stmt));
|
|
self.push_iterable_nodes(NodesToPush::Stmt(stmt));
|