compare parsed expressions instead of strings

This commit is contained in:
Evan Almloff committed 2022-05-26 19:21:53 -05:00
1 parent 5b0a60c294
commit 07da854455
3 files changed
+10 -9

No files matched your search

+1 -1
View File
@@ -20,7 +20,7 @@ fn app(cx: Scope) -> Element {
cx.render(rsx! {
h1 {
x: count,
width: format!("{}px", count),
"High-Five counter: {count}"
}
})
@@ -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
View File
@@ -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 }] } })