Use the correct to-static impl for sending escaped strings via hotreload (#2753)

This commit is contained in:
Jonathan Kelley authored and GitHub committed 2024-07-30 23:06:44 -05:00
1 parent 828cc502f1
commit 189772a17b
3 files changed
+16 -16

No files matched your search

+9
View File
@@ -408,4 +408,13 @@ mod tests {
println!("{}", input.to_string_with_quotes());
assert!(input.is_static());
}
#[test]
fn to_static() {
let input = syn::parse2::<IfmtInput>(quote! { "body {{ background: red; }}" }).unwrap();
assert_eq!(
input.to_static(),
Some("body { background: red; }".to_string())
);
}
}
+2 -9
View File
@@ -156,14 +156,7 @@ impl BodyNode {
),
}
}
BodyNode::Text(text) if text.is_static() => {
let text = text.input.source.clone();
let text = intern(text.value().as_str());
TemplateNode::Text { text }
}
BodyNode::Text(text) => TemplateNode::Dynamic {
id: text.dyn_idx.get(),
},
BodyNode::Text(text) => text.to_template_node(),
BodyNode::RawExpr(exp) => TemplateNode::Dynamic {
id: exp.dyn_idx.get(),
},
@@ -209,7 +202,7 @@ impl BodyNode {
match self {
BodyNode::Element(el) => el.name.span(),
BodyNode::Component(component) => component.name.span(),
BodyNode::Text(text) => text.input.source.span(),
BodyNode::Text(text) => text.input.span(),
BodyNode::RawExpr(exp) => exp.span(),
BodyNode::ForLoop(fl) => fl.for_token.span(),
BodyNode::IfChain(f) => f.if_token.span(),
+5 -7
View File
@@ -66,13 +66,11 @@ impl TextNode {
#[cfg(feature = "hot_reload")]
pub fn to_template_node(&self) -> TemplateNode {
use crate::intern;
match self.is_static() {
true => {
let text = self.input.source.clone();
let text = intern(text.value().as_str());
TemplateNode::Text { text }
}
false => TemplateNode::Dynamic {
match self.input.to_static() {
Some(text) => TemplateNode::Text {
text: intern(text.as_str()),
},
None => TemplateNode::Dynamic {
id: self.dyn_idx.get(),
},
}