|
@@ -3,6 +3,7 @@ use dioxus_rsx::*;
|
|
use proc_macro2::{LineColumn, Span};
|
|
use proc_macro2::{LineColumn, Span};
|
|
use quote::ToTokens;
|
|
use quote::ToTokens;
|
|
use std::{
|
|
use std::{
|
|
|
|
+ borrow::Cow,
|
|
collections::{HashMap, VecDeque},
|
|
collections::{HashMap, VecDeque},
|
|
fmt::{Result, Write},
|
|
fmt::{Result, Write},
|
|
};
|
|
};
|
|
@@ -910,9 +911,14 @@ impl<'a> Writer<'a> {
|
|
}
|
|
}
|
|
|
|
|
|
#[allow(clippy::map_entry)]
|
|
#[allow(clippy::map_entry)]
|
|
- fn retrieve_formatted_expr(&mut self, expr: &Expr) -> &str {
|
|
|
|
|
|
+ fn retrieve_formatted_expr(&mut self, expr: &Expr) -> Cow<'_, str> {
|
|
let loc = expr.span().start();
|
|
let loc = expr.span().start();
|
|
|
|
|
|
|
|
+ // never cache expressions that are spanless
|
|
|
|
+ if loc.line == 1 && loc.column == 0 {
|
|
|
|
+ return self.unparse_expr(expr).into();
|
|
|
|
+ }
|
|
|
|
+
|
|
if !self.cached_formats.contains_key(&loc) {
|
|
if !self.cached_formats.contains_key(&loc) {
|
|
let formatted = self.unparse_expr(expr);
|
|
let formatted = self.unparse_expr(expr);
|
|
self.cached_formats.insert(loc, formatted);
|
|
self.cached_formats.insert(loc, formatted);
|
|
@@ -922,6 +928,7 @@ impl<'a> Writer<'a> {
|
|
.get(&loc)
|
|
.get(&loc)
|
|
.expect("Just inserted the parsed expr, so it should be in the cache")
|
|
.expect("Just inserted the parsed expr, so it should be in the cache")
|
|
.as_str()
|
|
.as_str()
|
|
|
|
+ .into()
|
|
}
|
|
}
|
|
|
|
|
|
fn final_span_of_node(node: &BodyNode) -> Span {
|
|
fn final_span_of_node(node: &BodyNode) -> Span {
|