wip: move macro lib out of proc macro crate

This commit is contained in:
Jonathan Kelley committed 2022-01-17 16:37:44 -05:00
1 parent c08d04449f
commit abfac0d59b
16 files changed
+116 -47

No files matched your search

+4 -1
View File
@@ -14,6 +14,7 @@ keywords = ["dom", "ui", "gui", "react", "wasm"]
dioxus-core = { path = "./packages/core", version = "^0.1.7" } dioxus-core = { path = "./packages/core", version = "^0.1.7" }
dioxus-html = { path = "./packages/html", version = "^0.1.4", optional = true } dioxus-html = { path = "./packages/html", version = "^0.1.4", optional = true }
dioxus-core-macro = { path = "./packages/core-macro", version = "^0.1.6", optional = true } dioxus-core-macro = { path = "./packages/core-macro", version = "^0.1.6", optional = true }
dioxus-macro-inner = { path = "./packages/macro-inner", optional = true }
dioxus-hooks = { path = "./packages/hooks", version = "^0.1.6", optional = true } dioxus-hooks = { path = "./packages/hooks", version = "^0.1.6", optional = true }
dioxus-web = { path = "./packages/web", version = "^0.0.4", optional = true } dioxus-web = { path = "./packages/web", version = "^0.0.4", optional = true }
@@ -27,7 +28,7 @@ dioxus-mobile = { path = "./packages/mobile", version = "^0.0.3", optional = tru
[features] [features]
default = ["macro", "hooks", "html"] default = ["macro", "hooks", "html"]
macro = ["dioxus-core-macro"] macro = ["dioxus-core-macro", "dioxus-macro-inner"]
hooks = ["dioxus-hooks"] hooks = ["dioxus-hooks"]
html = ["dioxus-html"] html = ["dioxus-html"]
ssr = ["dioxus-ssr"] ssr = ["dioxus-ssr"]
@@ -35,6 +36,7 @@ web = ["dioxus-web"]
desktop = ["dioxus-desktop"] desktop = ["dioxus-desktop"]
router = ["dioxus-router"] router = ["dioxus-router"]
# "dioxus-router/web" # "dioxus-router/web"
# "dioxus-router/desktop" # "dioxus-router/desktop"
# desktop = ["dioxus-desktop", "dioxus-router/desktop"] # desktop = ["dioxus-desktop", "dioxus-router/desktop"]
@@ -46,6 +48,7 @@ router = ["dioxus-router"]
members = [ members = [
"packages/core", "packages/core",
"packages/core-macro", "packages/core-macro",
"packages/macro-inner",
"packages/html", "packages/html",
"packages/hooks", "packages/hooks",
"packages/web", "packages/web",
+27
View File
@@ -0,0 +1,27 @@
//! This example shows that autocomplete works in RSX
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(app);
}
fn app(cx: Scope) -> Element {
cx.render(rsx! {
div {
onclick: move |_| {
}
// class: "asd",
// style {
// media: "Ad",
// }
// div {
// }
// {
// let t = String::new();
// t.
// }
}
})
}
+1
View File
@@ -15,6 +15,7 @@ keywords = ["dom", "ui", "gui", "react", "wasm"]
proc-macro = true proc-macro = true
[dependencies] [dependencies]
dioxus-macro-inner = { path = "../macro-inner" }
once_cell = "1.8" once_cell = "1.8"
proc-macro-error = "1.0.4" proc-macro-error = "1.0.4"
proc-macro2 = { version = "1.0.6" } proc-macro2 = { version = "1.0.6" }
+1 -6
View File
@@ -1,13 +1,8 @@
use dioxus_macro_inner::*;
use proc_macro::TokenStream; use proc_macro::TokenStream;
use quote::ToTokens; use quote::ToTokens;
use syn::parse_macro_input; use syn::parse_macro_input;
pub(crate) mod ifmt;
pub(crate) mod inlineprops;
pub(crate) mod props;
pub(crate) mod router;
pub(crate) mod rsx;
#[proc_macro] #[proc_macro]
pub fn format_args_f(input: TokenStream) -> TokenStream { pub fn format_args_f(input: TokenStream) -> TokenStream {
use ifmt::*; use ifmt::*;
+13
View File
@@ -0,0 +1,13 @@
[package]
name = "dioxus-macro-inner"
version = "0.0.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
once_cell = "1.8"
proc-macro-error = "1.0.4"
proc-macro2 = { version = "1.0.6" }
quote = "1.0"
syn = { version = "1.0.11", features = ["full", "extra-traits"] }
File renamed without changes.
File renamed without changes.
+5
View File
@@ -0,0 +1,5 @@
pub mod ifmt;
pub mod inlineprops;
pub mod props;
pub mod router;
pub mod rsx;
File renamed without changes.
File renamed without changes.
@@ -23,10 +23,10 @@ use syn::{
}; };
pub struct Component { pub struct Component {
name: syn::Path, pub name: syn::Path,
body: Vec<ComponentField>, pub body: Vec<ComponentField>,
children: Vec<BodyNode>, pub children: Vec<BodyNode>,
manual_props: Option<Expr>, pub manual_props: Option<Expr>,
} }
impl Parse for Component { impl Parse for Component {
@@ -4,19 +4,18 @@ use proc_macro2::TokenStream as TokenStream2;
use quote::{quote, ToTokens, TokenStreamExt}; use quote::{quote, ToTokens, TokenStreamExt};
use syn::{ use syn::{
parse::{Parse, ParseBuffer, ParseStream}, parse::{Parse, ParseBuffer, ParseStream},
Expr, Ident, LitStr, Result, Token, Expr, ExprClosure, Ident, LitStr, Result, Token,
}; };
// ======================================= // =======================================
// Parse the VNode::Element type // Parse the VNode::Element type
// ======================================= // =======================================
pub struct Element { pub struct Element {
name: Ident, pub name: Ident,
key: Option<LitStr>, pub key: Option<LitStr>,
attributes: Vec<ElementAttrNamed>, pub attributes: Vec<ElementAttrNamed>,
listeners: Vec<ElementAttrNamed>, pub children: Vec<BodyNode>,
children: Vec<BodyNode>, pub _is_static: bool,
_is_static: bool,
} }
impl Parse for Element { impl Parse for Element {
@@ -28,7 +27,6 @@ impl Parse for Element {
syn::braced!(content in stream); syn::braced!(content in stream);
let mut attributes: Vec<ElementAttrNamed> = vec![]; let mut attributes: Vec<ElementAttrNamed> = vec![];
let mut listeners: Vec<ElementAttrNamed> = vec![];
let mut children: Vec<BodyNode> = vec![]; let mut children: Vec<BodyNode> = vec![];
let mut key = None; let mut key = None;
let mut _el_ref = None; let mut _el_ref = None;
@@ -54,6 +52,7 @@ impl Parse for Element {
}); });
} else { } else {
let value = content.parse::<Expr>()?; let value = content.parse::<Expr>()?;
attributes.push(ElementAttrNamed { attributes.push(ElementAttrNamed {
el_name: el_name.clone(), el_name: el_name.clone(),
attr: ElementAttr::CustomAttrExpression { name, value }, attr: ElementAttr::CustomAttrExpression { name, value },
@@ -82,13 +81,24 @@ impl Parse for Element {
content.parse::<Token![:]>()?; content.parse::<Token![:]>()?;
if name_str.starts_with("on") { if name_str.starts_with("on") {
listeners.push(ElementAttrNamed { if content.fork().parse::<ExprClosure>().is_ok() {
el_name: el_name.clone(), //
attr: ElementAttr::EventTokens { attributes.push(ElementAttrNamed {
name, el_name: el_name.clone(),
tokens: content.parse()?, attr: ElementAttr::EventClosure {
}, name,
}); closure: content.parse()?,
},
});
} else {
attributes.push(ElementAttrNamed {
el_name: el_name.clone(),
attr: ElementAttr::EventTokens {
name,
tokens: content.parse()?,
},
});
}
} else { } else {
match name_str.as_str() { match name_str.as_str() {
"key" => { "key" => {
@@ -182,7 +192,7 @@ impl Parse for Element {
name: el_name, name: el_name,
attributes, attributes,
children, children,
listeners, // listeners,
_is_static: false, _is_static: false,
}) })
} }
@@ -193,14 +203,29 @@ impl ToTokens for Element {
let name = &self.name; let name = &self.name;
let children = &self.children; let children = &self.children;
let listeners = &self.listeners; // let listeners = &self.listeners;
let attr = &self.attributes;
let key = match &self.key { let key = match &self.key {
Some(ty) => quote! { Some(format_args_f!(#ty)) }, Some(ty) => quote! { Some(format_args_f!(#ty)) },
None => quote! { None }, None => quote! { None },
}; };
let listeners = self.attributes.iter().filter(|f| {
if let ElementAttr::EventTokens { .. } = f.attr {
true
} else {
false
}
});
let attr = self.attributes.iter().filter(|f| {
if let ElementAttr::EventTokens { .. } = f.attr {
false
} else {
true
}
});
tokens.append_all(quote! { tokens.append_all(quote! {
__cx.element( __cx.element(
dioxus_elements::#name, dioxus_elements::#name,
@@ -213,29 +238,29 @@ impl ToTokens for Element {
} }
} }
enum ElementAttr { pub enum ElementAttr {
// attribute: "valuee {}" /// attribute: "valuee {}"
AttrText { name: Ident, value: LitStr }, AttrText { name: Ident, value: LitStr },
// attribute: true, /// attribute: true,
AttrExpression { name: Ident, value: Expr }, AttrExpression { name: Ident, value: Expr },
// "attribute": "value {}" /// "attribute": "value {}"
CustomAttrText { name: LitStr, value: LitStr }, CustomAttrText { name: LitStr, value: LitStr },
// "attribute": true, /// "attribute": true,
CustomAttrExpression { name: LitStr, value: Expr }, CustomAttrExpression { name: LitStr, value: Expr },
// // onclick: move |_| {} /// onclick: move |_| {}
// EventClosure { name: Ident, closure: ExprClosure }, EventClosure { name: Ident, closure: ExprClosure },
// onclick: {} /// onclick: {}
EventTokens { name: Ident, tokens: Expr }, EventTokens { name: Ident, tokens: Expr },
} }
struct ElementAttrNamed { pub struct ElementAttrNamed {
el_name: Ident, pub el_name: Ident,
attr: ElementAttr, pub attr: ElementAttr,
} }
impl ToTokens for ElementAttrNamed { impl ToTokens for ElementAttrNamed {
@@ -263,11 +288,11 @@ impl ToTokens for ElementAttrNamed {
__cx.attr( #name, format_args_f!(#value), None, false ) __cx.attr( #name, format_args_f!(#value), None, false )
} }
} }
// ElementAttr::EventClosure { name, closure } => { ElementAttr::EventClosure { name, closure } => {
// quote! { quote! {
// dioxus_elements::on::#name(__cx, #closure) dioxus_elements::on::#name(__cx, #closure)
// } }
// } }
ElementAttr::EventTokens { name, tokens } => { ElementAttr::EventTokens { name, tokens } => {
quote! { quote! {
dioxus_elements::on::#name(__cx, #tokens) dioxus_elements::on::#name(__cx, #tokens)
@@ -29,8 +29,8 @@ use syn::{
}; };
pub struct CallBody { pub struct CallBody {
custom_context: Option<Ident>, pub custom_context: Option<Ident>,
roots: Vec<BodyNode>, pub roots: Vec<BodyNode>,
} }
impl Parse for CallBody { impl Parse for CallBody {
File renamed without changes.