polish: remove warnings on core macero
This commit is contained in:
1 parent
b43a964f98
commit
6587224deb
10 files changed
+38
-96
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "dioxus-core-macro"
|
name = "dioxus-core-macro"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
authors = ["Jonathan Kelley <jkelleyrtp@gmail.com>"]
|
authors = ["Jonathan Kelley <jkelleyrtp@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Core macro for Dioxus Virtual DOM"
|
description = "Core macro for Dioxus Virtual DOM"
|
||||||
|
|||||||
@@ -14,13 +14,12 @@
|
|||||||
//!
|
//!
|
||||||
|
|
||||||
use {
|
use {
|
||||||
proc_macro::TokenStream,
|
proc_macro2::TokenStream as TokenStream2,
|
||||||
proc_macro2::{Span, TokenStream as TokenStream2},
|
|
||||||
quote::{quote, ToTokens, TokenStreamExt},
|
quote::{quote, ToTokens, TokenStreamExt},
|
||||||
syn::{
|
syn::{
|
||||||
ext::IdentExt,
|
ext::IdentExt,
|
||||||
parse::{Parse, ParseStream},
|
parse::{Parse, ParseStream},
|
||||||
token, Error, Expr, ExprClosure, Ident, LitBool, LitStr, Path, Result, Token,
|
token, Error, Expr, ExprClosure, Ident, LitStr, Result, Token,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -121,7 +120,7 @@ impl ToTokens for ToToksCtx<&Node> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Node {
|
impl Node {
|
||||||
fn peek(s: ParseStream) -> bool {
|
fn _peek(s: ParseStream) -> bool {
|
||||||
(s.peek(Token![<]) && !s.peek2(Token![/])) || s.peek(token::Brace) || s.peek(LitStr)
|
(s.peek(Token![<]) && !s.peek2(Token![/])) || s.peek(token::Brace) || s.peek(LitStr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,44 +7,12 @@ use ::syn::{
|
|||||||
};
|
};
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
|
|
||||||
// #[cfg(not(feature = "verbose-expansions"))]
|
|
||||||
macro_rules! debug_input {
|
|
||||||
($expr:expr) => {
|
|
||||||
$expr
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// #[cfg(not(feature = "verbose-expansions"))]
|
|
||||||
macro_rules! debug_output {
|
macro_rules! debug_output {
|
||||||
($expr:expr) => {
|
($expr:expr) => {
|
||||||
$expr
|
$expr
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[cfg(feature = "verbose-expansions")]
|
|
||||||
// macro_rules! debug_input {
|
|
||||||
// ($expr:expr) => {
|
|
||||||
// match $expr {
|
|
||||||
// expr => {
|
|
||||||
// eprintln!("-------------------\n{} ! ( {} )", FUNCTION_NAME, expr);
|
|
||||||
// expr
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #[cfg(feature = "verbose-expansions")]
|
|
||||||
// macro_rules! debug_output {
|
|
||||||
// ($expr:expr) => {
|
|
||||||
// match $expr {
|
|
||||||
// expr => {
|
|
||||||
// eprintln!("=>\n{}\n-------------------\n", expr);
|
|
||||||
// expr
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
pub fn format_args_f_impl(input: IfmtInput) -> Result<TokenStream> {
|
pub fn format_args_f_impl(input: IfmtInput) -> Result<TokenStream> {
|
||||||
let IfmtInput {
|
let IfmtInput {
|
||||||
mut format_literal,
|
mut format_literal,
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ use proc_macro2::TokenStream as TokenStream2;
|
|||||||
use quote::ToTokens;
|
use quote::ToTokens;
|
||||||
use syn::{
|
use syn::{
|
||||||
parse::{Parse, ParseStream},
|
parse::{Parse, ParseStream},
|
||||||
Error, Ident, LitStr, Result, Token,
|
Error, Ident, Result, Token,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub enum AmbiguousElement<const AS: HTML_OR_RSX> {
|
pub enum AmbiguousElement<const AS: HtmlOrRsx> {
|
||||||
Element(Element<AS>),
|
Element(Element<AS>),
|
||||||
Component(Component<AS>),
|
Component(Component<AS>),
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ impl Parse for AmbiguousElement<AS_HTML> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const AS: HTML_OR_RSX> ToTokens for AmbiguousElement<AS> {
|
impl<const AS: HtmlOrRsx> ToTokens for AmbiguousElement<AS> {
|
||||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||||
match self {
|
match self {
|
||||||
AmbiguousElement::Element(el) => el.to_tokens(tokens),
|
AmbiguousElement::Element(el) => el.to_tokens(tokens),
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ use proc_macro2::TokenStream as TokenStream2;
|
|||||||
use quote::{quote, ToTokens, TokenStreamExt};
|
use quote::{quote, ToTokens, TokenStreamExt};
|
||||||
use syn::{
|
use syn::{
|
||||||
parse::{Parse, ParseStream},
|
parse::{Parse, ParseStream},
|
||||||
Error, Ident, Result, Token,
|
Ident, Result, Token,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub struct RsxBody<const AS: HTML_OR_RSX> {
|
pub struct RsxBody<const AS: HtmlOrRsx> {
|
||||||
custom_context: Option<Ident>,
|
custom_context: Option<Ident>,
|
||||||
roots: Vec<BodyNode<AS>>,
|
roots: Vec<BodyNode<AS>>,
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ fn try_parse_custom_context(input: ParseStream) -> Result<Option<Ident>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Serialize the same way, regardless of flavor
|
/// Serialize the same way, regardless of flavor
|
||||||
impl<const A: HTML_OR_RSX> ToTokens for RsxBody<A> {
|
impl<const A: HtmlOrRsx> ToTokens for RsxBody<A> {
|
||||||
fn to_tokens(&self, out_tokens: &mut TokenStream2) {
|
fn to_tokens(&self, out_tokens: &mut TokenStream2) {
|
||||||
let inner = if self.roots.len() == 1 {
|
let inner = if self.roots.len() == 1 {
|
||||||
let inner = &self.roots[0];
|
let inner = &self.roots[0];
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use syn::{
|
|||||||
token, Error, Expr, ExprClosure, Ident, Result, Token,
|
token, Error, Expr, ExprClosure, Ident, Result, Token,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Component<const AS: HTML_OR_RSX> {
|
pub struct Component<const AS: HtmlOrRsx> {
|
||||||
// accept any path-like argument
|
// accept any path-like argument
|
||||||
name: syn::Path,
|
name: syn::Path,
|
||||||
body: Vec<ComponentField<AS>>,
|
body: Vec<ComponentField<AS>>,
|
||||||
@@ -82,13 +82,13 @@ impl Parse for Component<AS_HTML> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct BodyParseConfig<const AS: HTML_OR_RSX> {
|
pub struct BodyParseConfig<const AS: HtmlOrRsx> {
|
||||||
pub allow_fields: bool,
|
pub allow_fields: bool,
|
||||||
pub allow_children: bool,
|
pub allow_children: bool,
|
||||||
pub allow_manual_props: bool,
|
pub allow_manual_props: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const AS: HTML_OR_RSX> BodyParseConfig<AS> {
|
impl<const AS: HtmlOrRsx> BodyParseConfig<AS> {
|
||||||
/// The configuration to parse the root
|
/// The configuration to parse the root
|
||||||
pub fn new_as_body() -> Self {
|
pub fn new_as_body() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@@ -214,7 +214,7 @@ impl BodyParseConfig<AS_HTML> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const AS: HTML_OR_RSX> ToTokens for Component<AS> {
|
impl<const AS: HtmlOrRsx> ToTokens for Component<AS> {
|
||||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||||
let name = &self.name;
|
let name = &self.name;
|
||||||
|
|
||||||
@@ -284,7 +284,7 @@ impl<const AS: HTML_OR_RSX> ToTokens for Component<AS> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the struct's fields info
|
// the struct's fields info
|
||||||
pub struct ComponentField<const AS: HTML_OR_RSX> {
|
pub struct ComponentField<const AS: HtmlOrRsx> {
|
||||||
name: Ident,
|
name: Ident,
|
||||||
content: ContentField,
|
content: ContentField,
|
||||||
}
|
}
|
||||||
@@ -354,7 +354,7 @@ impl Parse for ComponentField<AS_HTML> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const AS: HTML_OR_RSX> ToTokens for ComponentField<AS> {
|
impl<const AS: HtmlOrRsx> ToTokens for ComponentField<AS> {
|
||||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||||
let ComponentField { name, content, .. } = self;
|
let ComponentField { name, content, .. } = self;
|
||||||
tokens.append_all(quote! {
|
tokens.append_all(quote! {
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ use syn::{
|
|||||||
// =======================================
|
// =======================================
|
||||||
// Parse the VNode::Element type
|
// Parse the VNode::Element type
|
||||||
// =======================================
|
// =======================================
|
||||||
pub struct Element<const AS: HTML_OR_RSX> {
|
pub struct Element<const AS: HtmlOrRsx> {
|
||||||
name: Ident,
|
name: Ident,
|
||||||
key: Option<LitStr>,
|
key: Option<LitStr>,
|
||||||
attributes: Vec<ElementAttr<AS>>,
|
attributes: Vec<ElementAttr<AS>>,
|
||||||
listeners: Vec<ElementAttr<AS>>,
|
listeners: Vec<ElementAttr<AS>>,
|
||||||
children: Vec<BodyNode<AS>>,
|
children: Vec<BodyNode<AS>>,
|
||||||
is_static: bool,
|
_is_static: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for Element<AS_RSX> {
|
impl Parse for Element<AS_RSX> {
|
||||||
@@ -66,31 +66,21 @@ impl Parse for Element<AS_RSX> {
|
|||||||
attributes,
|
attributes,
|
||||||
children,
|
children,
|
||||||
listeners,
|
listeners,
|
||||||
is_static: false,
|
_is_static: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for Element<AS_HTML> {
|
impl Parse for Element<AS_HTML> {
|
||||||
fn parse(stream: ParseStream) -> Result<Self> {
|
fn parse(stream: ParseStream) -> Result<Self> {
|
||||||
let l_tok = stream.parse::<Token![<]>()?;
|
let _l_tok = stream.parse::<Token![<]>()?;
|
||||||
let el_name = Ident::parse(stream)?;
|
let el_name = Ident::parse(stream)?;
|
||||||
|
|
||||||
// parse the guts
|
|
||||||
// let content: ParseBuffer;
|
|
||||||
// syn::braced!(content in stream);
|
|
||||||
|
|
||||||
let mut attributes: Vec<ElementAttr<AS_HTML>> = vec![];
|
let mut attributes: Vec<ElementAttr<AS_HTML>> = vec![];
|
||||||
let mut listeners: Vec<ElementAttr<AS_HTML>> = vec![];
|
let mut listeners: Vec<ElementAttr<AS_HTML>> = vec![];
|
||||||
let mut children: Vec<BodyNode<AS_HTML>> = vec![];
|
let children: Vec<BodyNode<AS_HTML>> = vec![];
|
||||||
let mut key = None;
|
let key = None;
|
||||||
|
|
||||||
// loop {
|
|
||||||
// if stream.peek(Token![>]) {
|
|
||||||
// break;
|
|
||||||
// } else {
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
while !stream.peek(Token![>]) {
|
while !stream.peek(Token![>]) {
|
||||||
// self-closing
|
// self-closing
|
||||||
if stream.peek(Token![/]) {
|
if stream.peek(Token![/]) {
|
||||||
@@ -101,7 +91,7 @@ impl Parse for Element<AS_HTML> {
|
|||||||
name: el_name,
|
name: el_name,
|
||||||
key: None,
|
key: None,
|
||||||
attributes,
|
attributes,
|
||||||
is_static: false,
|
_is_static: false,
|
||||||
listeners,
|
listeners,
|
||||||
children,
|
children,
|
||||||
});
|
});
|
||||||
@@ -186,12 +176,12 @@ impl Parse for Element<AS_HTML> {
|
|||||||
attributes,
|
attributes,
|
||||||
children,
|
children,
|
||||||
listeners,
|
listeners,
|
||||||
is_static: false,
|
_is_static: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const AS: HTML_OR_RSX> ToTokens for Element<AS> {
|
impl<const AS: HtmlOrRsx> ToTokens for Element<AS> {
|
||||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||||
let name = &self.name;
|
let name = &self.name;
|
||||||
let attr = &self.attributes;
|
let attr = &self.attributes;
|
||||||
@@ -217,7 +207,7 @@ impl<const AS: HTML_OR_RSX> ToTokens for Element<AS> {
|
|||||||
/// =======================================
|
/// =======================================
|
||||||
/// Parse a VElement's Attributes
|
/// Parse a VElement's Attributes
|
||||||
/// =======================================
|
/// =======================================
|
||||||
struct ElementAttr<const AS: HTML_OR_RSX> {
|
struct ElementAttr<const AS: HtmlOrRsx> {
|
||||||
element_name: Ident,
|
element_name: Ident,
|
||||||
name: Ident,
|
name: Ident,
|
||||||
value: AttrType,
|
value: AttrType,
|
||||||
@@ -346,13 +336,14 @@ fn parse_rsx_element_field(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const AS: HTML_OR_RSX> ToTokens for ElementAttr<AS> {
|
impl<const AS: HtmlOrRsx> ToTokens for ElementAttr<AS> {
|
||||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||||
let el_name = &self.element_name;
|
let el_name = &self.element_name;
|
||||||
let name_str = self.name.to_string();
|
|
||||||
let nameident = &self.name;
|
let nameident = &self.name;
|
||||||
|
|
||||||
let namespace = match &self.namespace {
|
// TODO: wire up namespace
|
||||||
|
let _name_str = self.name.to_string();
|
||||||
|
let _namespace = match &self.namespace {
|
||||||
Some(t) => quote! { Some(#t) },
|
Some(t) => quote! { Some(#t) },
|
||||||
None => quote! { None },
|
None => quote! { None },
|
||||||
};
|
};
|
||||||
@@ -376,15 +367,3 @@ impl<const AS: HTML_OR_RSX> ToTokens for ElementAttr<AS> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// __cx.attr(#name, format_args_f!(#value), #namespace, false)
|
|
||||||
//
|
|
||||||
// AttrType::BumpText(value) => tokens.append_all(quote! {
|
|
||||||
// __cx.attr(#name, format_args_f!(#value), #namespace, false)
|
|
||||||
// }),
|
|
||||||
// __cx.attr(#name_str, #exp, #namespace, false)
|
|
||||||
|
|
||||||
// AttrType::FieldTokens(exp) => tokens.append_all(quote! {
|
|
||||||
// dioxus_elements::#el_name.#nameident(__cx, format_args_f!(#value))
|
|
||||||
// __cx.attr(#name_str, #exp, #namespace, false)
|
|
||||||
// }),
|
|
||||||
@@ -8,22 +8,18 @@
|
|||||||
//! - [ ] Children
|
//! - [ ] Children
|
||||||
//! - [ ] Keys
|
//! - [ ] Keys
|
||||||
|
|
||||||
|
use super::{AmbiguousElement, HtmlOrRsx, AS_HTML, AS_RSX};
|
||||||
use syn::parse::ParseBuffer;
|
use syn::parse::ParseBuffer;
|
||||||
|
|
||||||
use super::{AmbiguousElement, AS_HTML, AS_RSX, HTML_OR_RSX};
|
|
||||||
|
|
||||||
use {
|
use {
|
||||||
proc_macro::TokenStream,
|
proc_macro2::TokenStream as TokenStream2,
|
||||||
proc_macro2::{Span, TokenStream as TokenStream2},
|
|
||||||
quote::{quote, ToTokens, TokenStreamExt},
|
quote::{quote, ToTokens, TokenStreamExt},
|
||||||
syn::{
|
syn::{
|
||||||
ext::IdentExt,
|
|
||||||
parse::{Parse, ParseStream},
|
parse::{Parse, ParseStream},
|
||||||
token, Error, Expr, ExprClosure, Ident, LitBool, LitStr, Path, Result, Token,
|
Ident, Result, Token,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Fragment<const AS: HTML_OR_RSX> {
|
pub struct Fragment<const AS: HtmlOrRsx> {
|
||||||
children: Vec<AmbiguousElement<AS>>,
|
children: Vec<AmbiguousElement<AS>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +63,7 @@ impl Parse for Fragment<AS_HTML> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const AS: HTML_OR_RSX> ToTokens for Fragment<AS> {
|
impl<const AS: HtmlOrRsx> ToTokens for Fragment<AS> {
|
||||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||||
let childs = &self.children;
|
let childs = &self.children;
|
||||||
let children = quote! {
|
let children = quote! {
|
||||||
|
|||||||
@@ -26,6 +26,6 @@ pub use element::*;
|
|||||||
pub use fragment::*;
|
pub use fragment::*;
|
||||||
pub use node::*;
|
pub use node::*;
|
||||||
|
|
||||||
pub type HTML_OR_RSX = bool;
|
pub(crate) type HtmlOrRsx = bool;
|
||||||
pub const AS_HTML: bool = true;
|
pub const AS_HTML: bool = true;
|
||||||
pub const AS_RSX: bool = false;
|
pub const AS_RSX: bool = false;
|
||||||
@@ -10,7 +10,7 @@ use syn::{
|
|||||||
// ==============================================
|
// ==============================================
|
||||||
// Parse any div {} as a VElement
|
// Parse any div {} as a VElement
|
||||||
// ==============================================
|
// ==============================================
|
||||||
pub enum BodyNode<const AS: HTML_OR_RSX> {
|
pub enum BodyNode<const AS: HtmlOrRsx> {
|
||||||
Element(AmbiguousElement<AS>),
|
Element(AmbiguousElement<AS>),
|
||||||
Text(TextNode),
|
Text(TextNode),
|
||||||
RawExpr(Expr),
|
RawExpr(Expr),
|
||||||
@@ -57,7 +57,7 @@ impl Parse for BodyNode<AS_HTML> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const AS: HTML_OR_RSX> ToTokens for BodyNode<AS> {
|
impl<const AS: HtmlOrRsx> ToTokens for BodyNode<AS> {
|
||||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||||
match &self {
|
match &self {
|
||||||
BodyNode::Element(el) => el.to_tokens(tokens),
|
BodyNode::Element(el) => el.to_tokens(tokens),
|
||||||
|
|||||||
Reference in new issue
Block a user