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
@@ -14,11 +14,12 @@
|
||||
use super::*;
|
||||
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
#[cfg(feature = "to_tokens")]
|
||||
use quote::{quote, ToTokens, TokenStreamExt};
|
||||
use syn::{
|
||||
ext::IdentExt,
|
||||
parse::{Parse, ParseBuffer, ParseStream},
|
||||
token, Expr, Ident, LitStr, Result, Token,
|
||||
token, Error, Expr, Ident, LitStr, Result, Token,
|
||||
};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
@@ -72,6 +73,7 @@ impl Parse for Component {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "to_tokens")]
|
||||
impl ToTokens for Component {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||
let name = &self.name;
|
||||
|
||||
+11
-29
@@ -1,10 +1,11 @@
|
||||
use super::*;
|
||||
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
#[cfg(feature = "to_tokens")]
|
||||
use quote::{quote, ToTokens, TokenStreamExt};
|
||||
use syn::{
|
||||
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() {
|
||||
missing_trailing_comma!(ident);
|
||||
missing_trailing_comma!(ident.span());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -123,7 +124,7 @@ impl Parse for Element {
|
||||
|
||||
// todo: add a message saying you need to include commas between fields
|
||||
if content.parse::<Token![,]>().is_err() {
|
||||
missing_trailing_comma!(ident);
|
||||
missing_trailing_comma!(ident.span());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -158,6 +159,7 @@ impl Parse for Element {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "to_tokens")]
|
||||
impl ToTokens for Element {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||
let name = &self.name;
|
||||
@@ -193,38 +195,21 @@ impl ToTokens for Element {
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub enum ElementAttr {
|
||||
/// attribute: "valuee {}"
|
||||
AttrText {
|
||||
name: Ident,
|
||||
value: LitStr,
|
||||
},
|
||||
AttrText { name: Ident, value: LitStr },
|
||||
|
||||
/// attribute: true,
|
||||
AttrExpression {
|
||||
name: Ident,
|
||||
value: Expr,
|
||||
},
|
||||
AttrExpression { name: Ident, value: Expr },
|
||||
|
||||
/// "attribute": "value {}"
|
||||
CustomAttrText {
|
||||
name: LitStr,
|
||||
value: LitStr,
|
||||
},
|
||||
CustomAttrText { name: LitStr, value: LitStr },
|
||||
|
||||
/// "attribute": true,
|
||||
CustomAttrExpression {
|
||||
name: LitStr,
|
||||
value: Expr,
|
||||
},
|
||||
CustomAttrExpression { name: LitStr, value: Expr },
|
||||
|
||||
// /// onclick: move |_| {}
|
||||
// EventClosure { name: Ident, closure: ExprClosure },
|
||||
/// onclick: {}
|
||||
EventTokens {
|
||||
name: Ident,
|
||||
tokens: Expr,
|
||||
},
|
||||
|
||||
Meta(String),
|
||||
EventTokens { name: Ident, tokens: Expr },
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
@@ -233,6 +218,7 @@ pub struct ElementAttrNamed {
|
||||
pub attr: ElementAttr,
|
||||
}
|
||||
|
||||
#[cfg(feature = "to_tokens")]
|
||||
impl ToTokens for ElementAttrNamed {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||
let ElementAttrNamed { el_name, attr } = self;
|
||||
@@ -268,10 +254,6 @@ impl ToTokens for ElementAttrNamed {
|
||||
dioxus_elements::on::#name(__cx, #tokens)
|
||||
}
|
||||
}
|
||||
|
||||
ElementAttr::Meta(_) => {
|
||||
todo!("meta attributes not supported yet");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,11 @@
|
||||
macro_rules! missing_trailing_comma {
|
||||
($span:expr) => {
|
||||
proc_macro_error::emit_error!($span, "missing trailing comma")
|
||||
return Err(Error::new($span, "missing trailing comma"));
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! attr_after_element {
|
||||
($span:expr) => {
|
||||
proc_macro_error::emit_error!(
|
||||
$span,
|
||||
"expected element";
|
||||
help = "move the attribute above all the children and text elements"
|
||||
)
|
||||
return Err(Error::new($span, "expected element\n = help move the attribute above all the children and text elements"));
|
||||
};
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
#[cfg(feature = "to_tokens")]
|
||||
use ::quote::{quote, ToTokens};
|
||||
use ::std::ops::Not;
|
||||
use ::syn::{
|
||||
@@ -7,6 +8,7 @@ use ::syn::{
|
||||
};
|
||||
use proc_macro2::TokenStream;
|
||||
|
||||
#[cfg(feature = "to_tokens")]
|
||||
pub fn format_args_f_impl(input: IfmtInput) -> Result<TokenStream> {
|
||||
let IfmtInput {
|
||||
format_literal,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use super::*;
|
||||
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
#[cfg(feature = "to_tokens")]
|
||||
use quote::{quote, ToTokens, TokenStreamExt};
|
||||
use syn::{
|
||||
parse::{Parse, ParseStream},
|
||||
@@ -21,7 +22,6 @@ pub enum BodyNode {
|
||||
Component(Component),
|
||||
Text(LitStr),
|
||||
RawExpr(Expr),
|
||||
Meta(String),
|
||||
}
|
||||
|
||||
impl BodyNode {
|
||||
@@ -79,6 +79,7 @@ impl Parse for BodyNode {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "to_tokens")]
|
||||
impl ToTokens for BodyNode {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||
match &self {
|
||||
@@ -90,7 +91,6 @@ impl ToTokens for BodyNode {
|
||||
BodyNode::RawExpr(exp) => tokens.append_all(quote! {
|
||||
__cx.fragment_from_iter(#exp)
|
||||
}),
|
||||
BodyNode::Meta(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user