Merge branch 'master' into jk/suspense-rollover

This commit is contained in:
Jonathan Kelley committed 2022-12-23 19:46:55 -05:00
commit 48b1bf2ac1
3 files changed
+2299 -849

No files matched your search

+2 -4
View File
@@ -1,5 +1,6 @@
use proc_macro::TokenStream;
use quote::ToTokens;
use rsx::RenderCallBody;
use syn::parse_macro_input;
mod inlineprops;
@@ -41,10 +42,7 @@ pub fn rsx(s: TokenStream) -> TokenStream {
pub fn render(s: TokenStream) -> TokenStream {
match syn::parse::<rsx::CallBody>(s) {
Err(err) => err.to_compile_error().into(),
Ok(mut body) => {
body.inline_cx = true;
body.into_token_stream().into()
}
Ok(body) => RenderCallBody(body).into_token_stream().into(),
}
}
File diff suppressed because it is too large. Load diff
+26 -21
View File
@@ -37,9 +37,6 @@ use syn::{
#[derive(Default, Debug)]
pub struct CallBody {
pub roots: Vec<BodyNode>,
// set this after
pub inline_cx: bool,
}
impl Parse for CallBody {
@@ -56,10 +53,7 @@ impl Parse for CallBody {
roots.push(node);
}
Ok(Self {
roots,
inline_cx: false,
})
Ok(Self { roots })
}
}
@@ -68,20 +62,29 @@ impl ToTokens for CallBody {
fn to_tokens(&self, out_tokens: &mut TokenStream2) {
let body = TemplateRenderer { roots: &self.roots };
if self.inline_cx {
out_tokens.append_all(quote! {
Some({
let __cx = cx;
#body
})
out_tokens.append_all(quote! {
::dioxus::core::LazyNodes::new( move | __cx: &::dioxus::core::ScopeState| -> ::dioxus::core::VNode {
#body
})
} else {
out_tokens.append_all(quote! {
::dioxus::core::LazyNodes::new( move | __cx: &::dioxus::core::ScopeState| -> ::dioxus::core::VNode {
#body
})
})
}
}
#[derive(Default, Debug)]
pub struct RenderCallBody(pub CallBody);
impl ToTokens for RenderCallBody {
fn to_tokens(&self, out_tokens: &mut TokenStream2) {
let body = TemplateRenderer {
roots: &self.0.roots,
};
out_tokens.append_all(quote! {
Some({
let __cx = cx;
#body
})
}
})
}
}
@@ -111,7 +114,10 @@ impl<'a> ToTokens for TemplateRenderer<'a> {
};
let spndbg = format!("{:?}", self.roots[0].span());
let root_col = spndbg[9..].split("..").next().unwrap();
let root_col = spndbg
.rsplit_once("..")
.and_then(|(_, after)| after.split_once(')').map(|(before, _)| before))
.unwrap_or_default();
let root_printer = self.roots.iter().enumerate().map(|(idx, root)| {
context.current_path.push(idx as u8);
@@ -148,7 +154,6 @@ impl<'a> ToTokens for TemplateRenderer<'a> {
key: #key_tokens,
template: TEMPLATE,
root_ids: std::cell::Cell::from_mut( __cx.bump().alloc([None; #num_roots]) as &mut _).as_slice_of_cells(),
// root_ids: std::cell::Cell::from_mut( __cx.bump().alloc([None; #num_roots]) as &mut [::dioxus::core::ElementId]).as_slice_of_cells(),
dynamic_nodes: __cx.bump().alloc([ #( #node_printer ),* ]),
dynamic_attrs: __cx.bump().alloc([ #( #dyn_attr_printer ),* ]),
}