瀏覽代碼

compare parsed expressions instead of strings

Evan Almloff 3 年之前
父節點
當前提交
07da854455

+ 1 - 1
examples/hot_reload.rs

@@ -20,7 +20,7 @@ fn app(cx: Scope) -> Element {
 
     cx.render(rsx! {
         h1 {
-            x: count,
+            width: format!("{}px", count),
             "High-Five counter: {count}"
         }
     })

+ 3 - 3
packages/rsx_interperter/src/captuered_context.rs

@@ -1,7 +1,7 @@
 use dioxus_core::VNode;
 use dioxus_rsx::{BodyNode, CallBody, Component, ElementAttr, IfmtInput};
 use quote::{quote, ToTokens, TokenStreamExt};
-use std::{any::Any, collections::HashMap};
+use std::collections::HashMap;
 use syn::Expr;
 
 #[derive(Default)]
@@ -41,7 +41,7 @@ impl CapturedContextBuilder {
                             let formated: IfmtInput = syn::parse2(value_tokens).unwrap();
                             captured.attributes.insert(name, formated);
                         }
-                        ElementAttr::AttrExpression { name, value } => {
+                        ElementAttr::AttrExpression { name: _, value } => {
                             captured.captured_expressions.push(value);
                         }
                         ElementAttr::CustomAttrText { name, value } => {
@@ -49,7 +49,7 @@ impl CapturedContextBuilder {
                             let formated: IfmtInput = syn::parse2(value_tokens).unwrap();
                             captured.attributes.insert(name, formated);
                         }
-                        ElementAttr::CustomAttrExpression { name, value } => {
+                        ElementAttr::CustomAttrExpression { name: _, value } => {
                             captured.captured_expressions.push(value);
                         }
                         _ => (),

+ 6 - 5
packages/rsx_interperter/src/interperter.rs

@@ -1,7 +1,7 @@
 use dioxus_core::{Attribute, NodeFactory, VNode};
 use dioxus_rsx::{BodyNode, CallBody, ElementAttr};
-use quote::ToTokens;
 use std::str::FromStr;
+use syn::{parse_str, Expr};
 
 use crate::attributes::attrbute_to_static_str;
 use crate::captuered_context::{CapturedContext, IfmtArgs};
@@ -145,9 +145,10 @@ fn build_node<'a>(
 
                             _ => unreachable!(),
                         };
-                        let formatted_expr = format!("{}", value.to_token_stream());
-                        if let Some((_, resulting_value)) =
-                            ctx.expressions.iter().find(|(n, _)| *n == formatted_expr)
+                        if let Some((_, resulting_value)) = ctx
+                            .expressions
+                            .iter()
+                            .find(|(n, _)| parse_str::<Expr>(*n).unwrap() == value)
                         {
                             if let Some((name, namespace)) = attrbute_to_static_str(&name) {
                                 let value = bump.alloc(resulting_value.clone());
@@ -160,7 +161,7 @@ fn build_node<'a>(
                                 });
                             }
                         } else {
-                            panic!("could not resolve expression {}", formatted_expr);
+                            panic!("could not resolve expression {:?}", value);
                         }
                     }
                     // Path(ExprPath { attrs: [], qself: None, path: Path { leading_colon: None, segments: [PathSegment { ident: Ident { ident: \"count\", span: #0 bytes(497..502) }, arguments: None }] } })