* create the dynamic value pool * assign ids to dynamic formatted segments * separate the rendering and literal pools * rsx output compiles again * more examples compiling with new rsx expansion * update template body explanation * all workspace examples compile * fix formatted segments in keys * start hot reload diffing * fix component literal hot reloading * start integrate new hot reloading with the CLI * simple hot reloads working * Fix hot reloading blocks with components * implement hot reloading for if chains * Fix hot reloading after a template requires a full rebuild * Fix hot reloading any attribute values * remove unsafe from hot reload utils * Fix hot reloading empty rsx * add more hot reloading tests * reorganize hot reload module * fix web hydration * fix empty rsx nodes in autoformatting * fix tests * remove path sorting logic from core * make template names more consistent in debug mode * fix quote_as_hot_reload_literal for explicitly typed literals * fix can_be_shorthand for string literals * fix formatted single dynamic expression * Fix usize component properties and playwright tests * remove default implementation for TemplateBody * add a bunch more comments for diffing, scoring and why this scoring system is optimal
46 lines
1.3 KiB
Rust
46 lines
1.3 KiB
Rust
#![allow(unused)]
|
|
|
|
#[cfg(feature = "hot_reload")]
|
|
use internment::Intern;
|
|
|
|
use proc_macro2::TokenStream as TokenStream2;
|
|
use std::{fmt::Debug, hash::Hash};
|
|
use syn::{
|
|
ext::IdentExt,
|
|
parse::{Parse, ParseBuffer},
|
|
Ident,
|
|
};
|
|
|
|
/// interns a object into a static object, reusing the value if it already exists
|
|
#[cfg(feature = "hot_reload")]
|
|
pub(crate) fn intern<T: Eq + Hash + Send + Sync + ?Sized + 'static>(
|
|
s: impl Into<Intern<T>>,
|
|
) -> &'static T {
|
|
s.into().as_ref()
|
|
}
|
|
|
|
/// These are just helpful methods for tests to pretty print the token stream - they are not used in the actual code
|
|
// #[cfg(test)]
|
|
pub trait PrettyUnparse {
|
|
fn pretty_unparse(&self) -> String;
|
|
}
|
|
|
|
// #[cfg(test)]
|
|
impl PrettyUnparse for TokenStream2 {
|
|
fn pretty_unparse(&self) -> String {
|
|
let parsed = syn::parse2::<syn::Expr>(self.clone()).unwrap();
|
|
prettier_please::unparse_expr(&parsed)
|
|
}
|
|
}
|
|
|
|
/// Parse a raw ident and return a new ident with the r# prefix added
|
|
pub fn parse_raw_ident(parse_buffer: &ParseBuffer) -> syn::Result<Ident> {
|
|
// First try to parse as a normal ident
|
|
if let Ok(ident) = Ident::parse(parse_buffer) {
|
|
return Ok(ident);
|
|
}
|
|
// If that fails, try to parse as a raw ident
|
|
let ident = Ident::parse_any(parse_buffer)?;
|
|
Ok(Ident::new_raw(&ident.to_string(), ident.span()))
|
|
}
|