allow rsx to be used outside of a proc_macro context
This commit is contained in:
1 parent
4b1ea5879d
commit
06390b9be5
8 files changed
+30
-46
No files matched your search
@@ -15,10 +15,9 @@ keywords = ["dom", "ui", "gui", "react", "wasm"]
|
|||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro-error = "1"
|
proc-macro2 = { version = "1.0" }
|
||||||
proc-macro2 = { version = "1.0.6" }
|
|
||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
syn = { version = "1.0.11", features = ["full", "extra-traits"] }
|
syn = { version = "1.0", features = ["full", "extra-traits"] }
|
||||||
dioxus-rsx = { path = "../rsx" }
|
dioxus-rsx = { path = "../rsx" }
|
||||||
dioxus-rsx-interperter = { path = "../rsx_interperter", optional = true }
|
dioxus-rsx-interperter = { path = "../rsx_interperter", optional = true }
|
||||||
|
|
||||||
@@ -28,4 +27,5 @@ rustversion = "1.0"
|
|||||||
trybuild = "1.0"
|
trybuild = "1.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
default = []
|
||||||
hot_reload = ["dioxus-rsx-interperter"]
|
hot_reload = ["dioxus-rsx-interperter"]
|
||||||
@@ -177,7 +177,6 @@ pub fn derive_typed_builder(input: proc_macro::TokenStream) -> proc_macro::Token
|
|||||||
/// todo!()
|
/// todo!()
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[proc_macro_error::proc_macro_error]
|
|
||||||
#[proc_macro]
|
#[proc_macro]
|
||||||
pub fn rsx(s: TokenStream) -> TokenStream {
|
pub fn rsx(s: TokenStream) -> TokenStream {
|
||||||
#[cfg(feature = "hot_reload")]
|
#[cfg(feature = "hot_reload")]
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ edition = "2018"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro2 = { version = "1.0.6" }
|
proc-macro2 = { version = "1.0" }
|
||||||
proc-macro-error = "1"
|
syn = { version = "1.0", features = ["full", "extra-traits"] }
|
||||||
quote = "1.0"
|
quote = { version = "1.0", optional = true }
|
||||||
syn = { version = "1.0.11", features = ["full", "extra-traits"] }
|
|
||||||
|
[features]
|
||||||
|
default = ["to_tokens"]
|
||||||
|
to_tokens = ["quote"]
|
||||||
@@ -14,11 +14,12 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use proc_macro2::TokenStream as TokenStream2;
|
use proc_macro2::TokenStream as TokenStream2;
|
||||||
|
#[cfg(feature = "to_tokens")]
|
||||||
use quote::{quote, ToTokens, TokenStreamExt};
|
use quote::{quote, ToTokens, TokenStreamExt};
|
||||||
use syn::{
|
use syn::{
|
||||||
ext::IdentExt,
|
ext::IdentExt,
|
||||||
parse::{Parse, ParseBuffer, ParseStream},
|
parse::{Parse, ParseBuffer, ParseStream},
|
||||||
token, Expr, Ident, LitStr, Result, Token,
|
token, Error, Expr, Ident, LitStr, Result, Token,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
@@ -72,6 +73,7 @@ impl Parse for Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "to_tokens")]
|
||||||
impl ToTokens for Component {
|
impl ToTokens for Component {
|
||||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||||
let name = &self.name;
|
let name = &self.name;
|
||||||
|
|||||||
+11
-29
@@ -1,10 +1,11 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use proc_macro2::TokenStream as TokenStream2;
|
use proc_macro2::TokenStream as TokenStream2;
|
||||||
|
#[cfg(feature = "to_tokens")]
|
||||||
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,
|
Error, Expr, Ident, LitStr, Result, Token,
|
||||||
};
|
};
|
||||||
|
|
||||||
// =======================================
|
// =======================================
|
||||||
@@ -65,7 +66,7 @@ impl Parse for Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if content.parse::<Token![,]>().is_err() {
|
if content.parse::<Token![,]>().is_err() {
|
||||||
missing_trailing_comma!(ident);
|
missing_trailing_comma!(ident.span());
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -123,7 +124,7 @@ impl Parse for Element {
|
|||||||
|
|
||||||
// todo: add a message saying you need to include commas between fields
|
// todo: add a message saying you need to include commas between fields
|
||||||
if content.parse::<Token![,]>().is_err() {
|
if content.parse::<Token![,]>().is_err() {
|
||||||
missing_trailing_comma!(ident);
|
missing_trailing_comma!(ident.span());
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -158,6 +159,7 @@ impl Parse for Element {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "to_tokens")]
|
||||||
impl ToTokens for Element {
|
impl ToTokens for Element {
|
||||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||||
let name = &self.name;
|
let name = &self.name;
|
||||||
@@ -193,38 +195,21 @@ impl ToTokens for Element {
|
|||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
pub enum ElementAttr {
|
pub enum ElementAttr {
|
||||||
/// attribute: "valuee {}"
|
/// attribute: "valuee {}"
|
||||||
AttrText {
|
AttrText { name: Ident, value: LitStr },
|
||||||
name: Ident,
|
|
||||||
value: LitStr,
|
|
||||||
},
|
|
||||||
|
|
||||||
/// attribute: true,
|
/// attribute: true,
|
||||||
AttrExpression {
|
AttrExpression { name: Ident, value: Expr },
|
||||||
name: Ident,
|
|
||||||
value: Expr,
|
|
||||||
},
|
|
||||||
|
|
||||||
/// "attribute": "value {}"
|
/// "attribute": "value {}"
|
||||||
CustomAttrText {
|
CustomAttrText { name: LitStr, value: LitStr },
|
||||||
name: LitStr,
|
|
||||||
value: LitStr,
|
|
||||||
},
|
|
||||||
|
|
||||||
/// "attribute": true,
|
/// "attribute": true,
|
||||||
CustomAttrExpression {
|
CustomAttrExpression { name: LitStr, value: Expr },
|
||||||
name: LitStr,
|
|
||||||
value: Expr,
|
|
||||||
},
|
|
||||||
|
|
||||||
// /// onclick: move |_| {}
|
// /// onclick: move |_| {}
|
||||||
// EventClosure { name: Ident, closure: ExprClosure },
|
// EventClosure { name: Ident, closure: ExprClosure },
|
||||||
/// onclick: {}
|
/// onclick: {}
|
||||||
EventTokens {
|
EventTokens { name: Ident, tokens: Expr },
|
||||||
name: Ident,
|
|
||||||
tokens: Expr,
|
|
||||||
},
|
|
||||||
|
|
||||||
Meta(String),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
@@ -233,6 +218,7 @@ pub struct ElementAttrNamed {
|
|||||||
pub attr: ElementAttr,
|
pub attr: ElementAttr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "to_tokens")]
|
||||||
impl ToTokens for ElementAttrNamed {
|
impl ToTokens for ElementAttrNamed {
|
||||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||||
let ElementAttrNamed { el_name, attr } = self;
|
let ElementAttrNamed { el_name, attr } = self;
|
||||||
@@ -268,10 +254,6 @@ impl ToTokens for ElementAttrNamed {
|
|||||||
dioxus_elements::on::#name(__cx, #tokens)
|
dioxus_elements::on::#name(__cx, #tokens)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ElementAttr::Meta(_) => {
|
|
||||||
todo!("meta attributes not supported yet");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,11 @@
|
|||||||
macro_rules! missing_trailing_comma {
|
macro_rules! missing_trailing_comma {
|
||||||
($span:expr) => {
|
($span:expr) => {
|
||||||
proc_macro_error::emit_error!($span, "missing trailing comma")
|
return Err(Error::new($span, "missing trailing comma"));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! attr_after_element {
|
macro_rules! attr_after_element {
|
||||||
($span:expr) => {
|
($span:expr) => {
|
||||||
proc_macro_error::emit_error!(
|
return Err(Error::new($span, "expected element\n = help move the attribute above all the children and text elements"));
|
||||||
$span,
|
|
||||||
"expected element";
|
|
||||||
help = "move the attribute above all the children and text elements"
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#[cfg(feature = "to_tokens")]
|
||||||
use ::quote::{quote, ToTokens};
|
use ::quote::{quote, ToTokens};
|
||||||
use ::std::ops::Not;
|
use ::std::ops::Not;
|
||||||
use ::syn::{
|
use ::syn::{
|
||||||
@@ -7,6 +8,7 @@ use ::syn::{
|
|||||||
};
|
};
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
|
|
||||||
|
#[cfg(feature = "to_tokens")]
|
||||||
pub fn format_args_f_impl(input: IfmtInput) -> Result<TokenStream> {
|
pub fn format_args_f_impl(input: IfmtInput) -> Result<TokenStream> {
|
||||||
let IfmtInput {
|
let IfmtInput {
|
||||||
format_literal,
|
format_literal,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use proc_macro2::TokenStream as TokenStream2;
|
use proc_macro2::TokenStream as TokenStream2;
|
||||||
|
#[cfg(feature = "to_tokens")]
|
||||||
use quote::{quote, ToTokens, TokenStreamExt};
|
use quote::{quote, ToTokens, TokenStreamExt};
|
||||||
use syn::{
|
use syn::{
|
||||||
parse::{Parse, ParseStream},
|
parse::{Parse, ParseStream},
|
||||||
@@ -21,7 +22,6 @@ pub enum BodyNode {
|
|||||||
Component(Component),
|
Component(Component),
|
||||||
Text(LitStr),
|
Text(LitStr),
|
||||||
RawExpr(Expr),
|
RawExpr(Expr),
|
||||||
Meta(String),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BodyNode {
|
impl BodyNode {
|
||||||
@@ -79,6 +79,7 @@ impl Parse for BodyNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "to_tokens")]
|
||||||
impl ToTokens for BodyNode {
|
impl ToTokens for BodyNode {
|
||||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||||
match &self {
|
match &self {
|
||||||
@@ -90,7 +91,6 @@ impl ToTokens for BodyNode {
|
|||||||
BodyNode::RawExpr(exp) => tokens.append_all(quote! {
|
BodyNode::RawExpr(exp) => tokens.append_all(quote! {
|
||||||
__cx.fragment_from_iter(#exp)
|
__cx.fragment_from_iter(#exp)
|
||||||
}),
|
}),
|
||||||
BodyNode::Meta(_) => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user