Merge pull request #675 from DioxusLabs/jk/global-attributes-refactor

tweak global attributes to follow the hot reloading PR, fix hovers actually showing, render doesnt throw errors anymore
This commit is contained in:
Jon Kelley authored and GitHub committed 2022-12-23 18:33:24 -05:00
commit a0b0558624
3 files changed
+2239 -797

No files matched your search

+2 -4
View File
@@ -1,5 +1,6 @@
use proc_macro::TokenStream; use proc_macro::TokenStream;
use quote::ToTokens; use quote::ToTokens;
use rsx::RenderCallBody;
use syn::parse_macro_input; use syn::parse_macro_input;
mod inlineprops; mod inlineprops;
@@ -41,10 +42,7 @@ pub fn rsx(s: TokenStream) -> TokenStream {
pub fn render(s: TokenStream) -> TokenStream { pub fn render(s: TokenStream) -> TokenStream {
match syn::parse::<rsx::CallBody>(s) { match syn::parse::<rsx::CallBody>(s) {
Err(err) => err.to_compile_error().into(), Err(err) => err.to_compile_error().into(),
Ok(mut body) => { Ok(body) => RenderCallBody(body).into_token_stream().into(),
body.inline_cx = true;
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)] #[derive(Default, Debug)]
pub struct CallBody { pub struct CallBody {
pub roots: Vec<BodyNode>, pub roots: Vec<BodyNode>,
// set this after
pub inline_cx: bool,
} }
impl Parse for CallBody { impl Parse for CallBody {
@@ -56,10 +53,7 @@ impl Parse for CallBody {
roots.push(node); roots.push(node);
} }
Ok(Self { Ok(Self { roots })
roots,
inline_cx: false,
})
} }
} }
@@ -68,20 +62,29 @@ impl ToTokens for CallBody {
fn to_tokens(&self, out_tokens: &mut TokenStream2) { fn to_tokens(&self, out_tokens: &mut TokenStream2) {
let body = TemplateRenderer { roots: &self.roots }; let body = TemplateRenderer { roots: &self.roots };
if self.inline_cx { out_tokens.append_all(quote! {
out_tokens.append_all(quote! { ::dioxus::core::LazyNodes::new( move | __cx: &::dioxus::core::ScopeState| -> ::dioxus::core::VNode {
Some({ #body
let __cx = cx;
#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 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)| { let root_printer = self.roots.iter().enumerate().map(|(idx, root)| {
context.current_path.push(idx as u8); context.current_path.push(idx as u8);
@@ -148,7 +154,6 @@ impl<'a> ToTokens for TemplateRenderer<'a> {
key: #key_tokens, key: #key_tokens,
template: TEMPLATE, 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 _).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_nodes: __cx.bump().alloc([ #( #node_printer ),* ]),
dynamic_attrs: __cx.bump().alloc([ #( #dyn_attr_printer ),* ]), dynamic_attrs: __cx.bump().alloc([ #( #dyn_attr_printer ),* ]),
} }