diff --git a/packages/core-macro/src/htm.rs b/packages/core-macro/src/htm.rs index 88f8cb0a9..ca53096f6 100644 --- a/packages/core-macro/src/htm.rs +++ b/packages/core-macro/src/htm.rs @@ -175,7 +175,7 @@ impl ToTokens for ToToksCtx<&Element> { if let Some(child) = children.next() { let mut inner_toks = TokenStream2::new(); self.recurse(child).to_tokens(&mut inner_toks); - while let Some(child) = children.next() { + for child in children { quote!(,).to_tokens(&mut inner_toks); self.recurse(child).to_tokens(&mut inner_toks); } @@ -234,7 +234,7 @@ impl Parse for Element { s.parse::()?; s.parse::()?; let close = Ident::parse_any(s)?; - if close.to_string() != name.to_string() { + if close != name { return Err(Error::new_spanned( close, "closing element does not match opening", @@ -271,7 +271,7 @@ impl Parse for Attr { // If so, parse into literal tokens let ty = if name_str.starts_with("on") { // remove the "on" bit - name = Ident::new(&name_str.trim_start_matches("on"), name.span()); + name = Ident::new(name_str.trim_start_matches("on"), name.span()); let content; syn::braced!(content in s); // AttrType::Value(content.parse()?) @@ -359,6 +359,7 @@ impl ToTokens for ToToksCtx<&TextNode> { } } +#[allow(clippy::large_enum_variant)] enum MaybeExpr { Literal(T), Expr(Expr), diff --git a/packages/core-macro/src/ifmt.rs b/packages/core-macro/src/ifmt.rs index 58d88fb78..71b8bdee6 100644 --- a/packages/core-macro/src/ifmt.rs +++ b/packages/core-macro/src/ifmt.rs @@ -7,12 +7,6 @@ use ::syn::{ }; use proc_macro2::TokenStream; -macro_rules! debug_output { - ($expr:expr) => { - $expr - }; -} - pub fn format_args_f_impl(input: IfmtInput) -> Result { let IfmtInput { mut format_literal, @@ -21,7 +15,7 @@ pub fn format_args_f_impl(input: IfmtInput) -> Result { } = input; let s = format_literal.value(); - let ref mut out_format_literal = String::with_capacity(s.len()); + let out_format_literal = &mut String::with_capacity(s.len()); let mut iterator = s.char_indices().peekable(); while let Some((i, c)) = iterator.next() { @@ -135,13 +129,13 @@ pub fn format_args_f_impl(input: IfmtInput) -> Result { }); format_literal = LitStr::new(out_format_literal, format_literal.span()); - Ok(TokenStream::from(debug_output!(quote! { + Ok(quote! { format_args!( #format_literal #(, #positional_args)* #(, #named_args)* ) - }))) + }) } #[allow(dead_code)] // dumb compiler does not see the struct being used... @@ -199,7 +193,7 @@ where where Drop: FnOnce(T), { - fn drop(self: &'_ mut Self) { + fn drop(&'_ mut self) { use ::core::ptr; unsafe { // # Safety @@ -217,7 +211,7 @@ where { type Target = T; #[inline] - fn deref(self: &'_ Self) -> &'_ Self::Target { + fn deref(&'_ self) -> &'_ Self::Target { &self.0 } } @@ -226,7 +220,7 @@ where Drop: FnOnce(T), { #[inline] - fn deref_mut(self: &'_ mut Self) -> &'_ mut Self::Target { + fn deref_mut(&'_ mut self) -> &'_ mut Self::Target { &mut self.0 } } diff --git a/packages/core-macro/src/rsx/ambiguous.rs b/packages/core-macro/src/rsx/ambiguous.rs index cfa90fb10..f1ed461e8 100644 --- a/packages/core-macro/src/rsx/ambiguous.rs +++ b/packages/core-macro/src/rsx/ambiguous.rs @@ -15,6 +15,7 @@ use syn::{ Error, Ident, Result, Token, }; +#[allow(clippy::large_enum_variant)] pub enum AmbiguousElement { Element(Element), Component(Component), @@ -30,7 +31,6 @@ impl Parse for AmbiguousElement { } // If not an absolute path, then parse the ident and check if it's a valid tag - if let Ok(pat) = input.fork().parse::() { if pat.segments.len() > 1 { return input @@ -80,57 +80,6 @@ impl Parse for AmbiguousElement { } else { Err(Error::new(input.span(), "Not a valid Html tag")) } - - // input.parse::]>()?; - - // let mut children = Vec::new(); - // while !input.peek(Token![<]) { - // children.push(input.parse::>()?); - // } - - // Ok(AmbiguousElement::Element(Element { - // name, - // key: todo!(), - // attributes: todo!(), - // listeners: todo!(), - // children, - // _is_static: todo!(), - // })) - - // // Try to parse as an absolute path and immediately defer to the componetn - // if input.peek(Token![::]) { - // return input - // .parse::>() - // .map(AmbiguousElement::Component); - // } - - // // If not an absolute path, then parse the ident and check if it's a valid tag - - // if let Ok(pat) = input.fork().parse::() { - // if pat.segments.len() > 1 { - // return input - // .parse::>() - // .map(AmbiguousElement::Component); - // } - // } - - // use syn::ext::IdentExt; - // if let Ok(name) = input.fork().call(Ident::parse_any) { - // let name_str = name.to_string(); - - // let first_char = name_str.chars().next().unwrap(); - // if first_char.is_ascii_uppercase() { - // input - // .parse::>() - // .map(AmbiguousElement::Component) - // } else { - // input - // .parse::>() - // .map(AmbiguousElement::Element) - // } - // } else { - // Err(Error::new(input.span(), "Not a valid Html tag")) - // } } } diff --git a/packages/core-macro/src/rsx/component.rs b/packages/core-macro/src/rsx/component.rs index 8b7d863dc..f28130e6b 100644 --- a/packages/core-macro/src/rsx/component.rs +++ b/packages/core-macro/src/rsx/component.rs @@ -91,7 +91,7 @@ impl Parse for Component { stream.parse::]>()?; 'parsing: loop { - if stream.peek(Token![<]) { + if stream.peek(Token![<]) && stream.peek2(Token![/]) { break 'parsing; } @@ -115,18 +115,6 @@ impl Parse for Component { } stream.parse::]>()?; - // // parse the guts - // let content: ParseBuffer; - // syn::braced!(content in stream); - - // let cfg: BodyConfig = BodyConfig { - // allow_children: true, - // allow_fields: true, - // allow_manual_props: true, - // }; - - // let (body, children, manual_props) = cfg.parse_component_body(&content)?; - Ok(Self { name, body, @@ -281,7 +269,7 @@ impl ToTokens for Component { let mut __manual_props = #manual_props; }; for field in &self.body { - if field.name.to_string() == "key" { + if field.name == "key" { has_key = Some(field); } else { let name = &field.name; @@ -301,7 +289,7 @@ impl ToTokens for Component { None => { let mut toks = quote! { fc_to_builder(#name) }; for field in &self.body { - if field.name.to_string() == "key" { + if field.name == "key" { has_key = Some(field); } else { toks.append_all(quote! {#field}) diff --git a/packages/core-macro/src/rsx/element.rs b/packages/core-macro/src/rsx/element.rs index aa7893092..865b8e814 100644 --- a/packages/core-macro/src/rsx/element.rs +++ b/packages/core-macro/src/rsx/element.rs @@ -137,10 +137,11 @@ impl Parse for Element { } }; } + stream.parse::]>()?; 'parsing: loop { - if stream.peek(Token![<]) { + if stream.peek(Token![<]) && stream.peek2(Token![/]) { break 'parsing; } @@ -155,6 +156,7 @@ impl Parse for Element { // closing element stream.parse::()?; stream.parse::()?; + let close = Ident::parse_any(stream)?; if close != el_name { return Err(Error::new_spanned( @@ -233,8 +235,6 @@ fn parse_rsx_element_field( // Return early if the field is a listener if name_str.starts_with("on") { // remove the "on" bit - // name = Ident::new(&name_str.trim_start_matches("on"), name.span()); - let ty = if stream.peek(token::Brace) { let content; syn::braced!(content in stream); @@ -293,7 +293,7 @@ fn parse_rsx_element_field( return Ok(()); } "classes" => { - todo!("custom class lsit not supported") + todo!("custom class list not supported") } "namespace" => { todo!("custom namespace not supported") @@ -346,11 +346,11 @@ impl ToTokens for ElementAttr { AttrType::BumpText(value) => tokens.append_all(quote! { dioxus_elements::#el_name.#nameident(__cx, format_args_f!(#value)) }), + AttrType::FieldTokens(exp) => tokens.append_all(quote! { dioxus_elements::#el_name.#nameident(__cx, #exp) }), - // todo: move event handlers on to the elements or onto the nodefactory AttrType::Event(event) => tokens.append_all(quote! { dioxus::events::on::#nameident(__cx, #event) }), diff --git a/packages/core-macro/src/rsx/mod.rs b/packages/core-macro/src/rsx/mod.rs index a9c6b824a..57f3d9bf7 100644 --- a/packages/core-macro/src/rsx/mod.rs +++ b/packages/core-macro/src/rsx/mod.rs @@ -17,7 +17,6 @@ mod component; mod element; mod fragment; mod node; -mod parse_rsx; // Re-export the namespaces into each other pub use ambiguous::*; diff --git a/packages/core-macro/src/rsx/parse_rsx.rs b/packages/core-macro/src/rsx/parse_rsx.rs deleted file mode 100644 index 4b5c55c59..000000000 --- a/packages/core-macro/src/rsx/parse_rsx.rs +++ /dev/null @@ -1,2 +0,0 @@ -struct CallBody {} -pub fn parse_callbody() {} diff --git a/packages/core/examples/syntax.rs b/packages/core/examples/syntax.rs index 5b9879045..0c1674c8d 100644 --- a/packages/core/examples/syntax.rs +++ b/packages/core/examples/syntax.rs @@ -11,20 +11,28 @@ fn html_usage() { let r = html! {
"hello world" +
+
+
"hello world" - "hello world" - "hello world" + +
}; + let r = rsx! { + div { + "hello world" + } + }; } fn rsx_uage() { - let r = html! { - - "hello world" - "hello world" - "hello world" - "hello world" - - }; + // let r = html! { + // + // "hello world" + // "hello world" + // "hello world" + // "hello world" + // + // }; }