Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "dioxus-core-macro"
version = { workspace = true }
authors = ["Jonathan Kelley"]
edition = "2021"
edition = "2024"
description = "Core macro for Dioxus Virtual DOM"
license = "MIT OR Apache-2.0"
repository = "https://github.com/DioxusLabs/dioxus/"
Expand Down
20 changes: 10 additions & 10 deletions packages/core-macro/src/component.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use proc_macro2::TokenStream;
use quote::{format_ident, quote, ToTokens, TokenStreamExt};
use quote::{ToTokens, TokenStreamExt, format_ident, quote};
use syn::parse::{Parse, ParseStream};
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
Expand Down Expand Up @@ -349,20 +349,20 @@ impl ComponentBody {
}

fn is_explicit_props_ident(&self) -> bool {
if let Some(FnArg::Typed(PatType { pat, .. })) = self.item_fn.sig.inputs.first() {
if let Pat::Ident(ident) = pat.as_ref() {
return ident.ident == "props";
}
if let Some(FnArg::Typed(PatType { pat, .. })) = self.item_fn.sig.inputs.first()
&& let Pat::Ident(ident) = pat.as_ref()
{
return ident.ident == "props";
}

false
}

fn has_struct_parameter_pattern(&self) -> bool {
if let Some(FnArg::Typed(PatType { pat, .. })) = self.item_fn.sig.inputs.first() {
if matches!(pat.as_ref(), Pat::Struct(_)) {
return true;
}
if let Some(FnArg::Typed(PatType { pat, .. })) = self.item_fn.sig.inputs.first()
&& matches!(pat.as_ref(), Pat::Struct(_))
{
return true;
}

false
Expand Down Expand Up @@ -575,7 +575,7 @@ fn rebind_mutability(f: &FnArg) -> TokenStream {
fn strip_pat_mutability(pat: &Pat) -> Pat {
let mut pat = pat.clone();
// rip off mutability, but still write it out eventually
if let Pat::Ident(ref mut pat_ident) = &mut pat {
if let Pat::Ident(pat_ident) = &mut pat {
pat_ident.mutability = None;
}

Expand Down
50 changes: 25 additions & 25 deletions packages/core-macro/src/props/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use proc_macro2::TokenStream;

use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::{parse::Error, PathArguments};
use syn::{PathArguments, parse::Error};

use quote::quote;
use syn::{parse_quote, GenericArgument, Ident, PathSegment, Type};
use syn::{GenericArgument, Ident, PathSegment, Type, parse_quote};

pub fn impl_my_derive(ast: &syn::DeriveInput) -> Result<TokenStream, Error> {
let data = match &ast.data {
Expand Down Expand Up @@ -53,20 +53,20 @@ pub fn impl_my_derive(ast: &syn::DeriveInput) -> Result<TokenStream, Error> {
return Err(Error::new(
ast.span(),
"Props is not supported for tuple structs",
))
));
}
syn::Fields::Unit => {
return Err(Error::new(
ast.span(),
"Props is not supported for unit structs",
))
));
}
},
syn::Data::Enum(_) => {
return Err(Error::new(ast.span(), "Props is not supported for enums"))
return Err(Error::new(ast.span(), "Props is not supported for enums"));
}
syn::Data::Union(_) => {
return Err(Error::new(ast.span(), "Props is not supported for unions"))
return Err(Error::new(ast.span(), "Props is not supported for unions"));
}
};
Ok(data)
Expand Down Expand Up @@ -176,8 +176,8 @@ mod field_info {
use proc_macro2::TokenStream;
use quote::{format_ident, quote};
use syn::spanned::Spanned;
use syn::{Expr, Path, parse_quote};
use syn::{parse::Error, punctuated::Punctuated};
use syn::{parse_quote, Expr, Path};

use super::util::{
expr_to_single_string, ident_to_type, path_to_single_string, strip_raw_ident_prefix,
Expand Down Expand Up @@ -551,11 +551,11 @@ fn extract_inner_type_from_segment(segment: &PathSegment) -> Option<&Type> {
mod struct_info {
use convert_case::{Case, Casing};
use proc_macro2::TokenStream;
use quote::{quote, ToTokens};
use quote::{ToTokens, quote};
use syn::parse::Error;
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::{parse_quote, Expr, Ident};
use syn::{Expr, Ident, parse_quote};

use crate::props::strip_option;

Expand Down Expand Up @@ -767,11 +767,11 @@ mod struct_info {

pub fn builder_creation_impl(&self) -> Result<TokenStream, Error> {
let StructInfo {
ref vis,
ref name,
ref builder_name,
vis,
name,
builder_name,
..
} = *self;
} = self;

let generics = self.generics.clone();
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
Expand Down Expand Up @@ -833,8 +833,8 @@ Finally, call `.build()` to create the instance of `{name}`.
Some(ref doc) => quote!(#[doc = #doc]),
None => {
let doc = format!(
"Builder for [`{name}`] instances.\n\nSee [`{name}::builder()`] for more info.",
);
"Builder for [`{name}`] instances.\n\nSee [`{name}::builder()`] for more info.",
);
quote!(#[doc = #doc])
}
}
Expand Down Expand Up @@ -1072,7 +1072,10 @@ Finally, call `.build()` to create the instance of `{name}`.
name: field_name, ..
} = field;
if *field_name == "key" {
return Err(Error::new_spanned(field_name, "Naming a prop `key` is not allowed because the name can conflict with the built in key attribute. See https://dioxuslabs.com/learn/0.7/essentials/ui/iteration for more information about keys"));
return Err(Error::new_spanned(
field_name,
"Naming a prop `key` is not allowed because the name can conflict with the built in key attribute. See https://dioxuslabs.com/learn/0.7/essentials/ui/iteration for more information about keys",
));
}
let StructInfo {
ref builder_name, ..
Expand Down Expand Up @@ -1235,14 +1238,11 @@ Finally, call `.build()` to create the instance of `{name}`.

pub fn required_field_impl(&self, field: &FieldInfo) -> Result<TokenStream, Error> {
let StructInfo {
ref name,
ref builder_name,
..
name, builder_name, ..
} = self;

let FieldInfo {
name: ref field_name,
..
name: field_name, ..
} = field;
let mut builder_generics: Vec<syn::GenericArgument> = self
.generics
Expand Down Expand Up @@ -1732,10 +1732,10 @@ fn strip_option(type_: &Type) -> Option<Type> {
let option_segment = segments_iter.next()?;
if option_segment.ident == "Option" && segments_iter.next().is_none() {
// It should have a single generic argument
if let PathArguments::AngleBracketed(generic_arg) = &option_segment.arguments {
if let Some(syn::GenericArgument::Type(ty)) = generic_arg.args.first() {
return Some(ty.clone());
}
if let PathArguments::AngleBracketed(generic_arg) = &option_segment.arguments
&& let Some(syn::GenericArgument::Type(ty)) = generic_arg.args.first()
{
return Some(ty.clone());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core-macro/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use quote::ToTokens;
use syn::parse::{Parse, ParseStream};
use syn::spanned::Spanned;
use syn::{parse_quote, Expr, Lit, Meta, Token, Type};
use syn::{Expr, Lit, Meta, Token, Type, parse_quote};

/// Attempts to convert the given literal to a string.
/// Converts ints and floats to their base 10 counterparts.
Expand Down
8 changes: 6 additions & 2 deletions packages/core/tests/diff_dynamic_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ use pretty_assertions::assert_eq;
#[test]
fn toggle_option_text() {
let mut dom = VirtualDom::new(|| {
let gen = generation();
let text = if gen % 2 != 0 { Some("hello") } else { None };
let generation_count = generation();
let text = if generation_count % 2 != 0 {
Some("hello")
} else {
None
};
println!("{:?}", text);

rsx! {
Expand Down
12 changes: 6 additions & 6 deletions packages/core/tests/diff_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use dioxus_core::generation;
#[test]
fn text_diff() {
fn app() -> Element {
let gen = generation();
rsx!( h1 { "hello {gen}" } )
let generation_count = generation();
rsx!( h1 { "hello {generation_count}" } )
}

let mut vdom = VirtualDom::new(app);
Expand Down Expand Up @@ -35,9 +35,9 @@ fn text_diff() {
#[test]
fn element_swap() {
fn app() -> Element {
let gen = generation();
let generation_count = generation();

match gen % 2 {
match generation_count % 2 {
0 => rsx!( h1 { "hello 1" } ),
1 => rsx!( h2 { "hello 2" } ),
_ => unreachable!(),
Expand Down Expand Up @@ -87,10 +87,10 @@ fn element_swap() {
#[test]
fn attribute_diff() {
fn app() -> Element {
let gen = generation();
let generation_count = generation();

// attributes have to be sorted by name
let attrs = match gen % 5 {
let attrs = match generation_count % 5 {
0 => vec![Attribute::new(
"a",
AttributeValue::Text("hello".into()),
Expand Down
12 changes: 6 additions & 6 deletions packages/core/tests/diff_unkeyed_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use pretty_assertions::assert_eq;
#[test]
fn list_creates_one_by_one() {
let mut dom = VirtualDom::new(|| {
let gen = generation();
let generation_count = generation();

rsx! {
div {
for i in 0..gen {
for i in 0..generation_count {
div { "{i}" }
}
}
Expand Down Expand Up @@ -82,11 +82,11 @@ fn list_creates_one_by_one() {
#[test]
fn removes_one_by_one() {
let mut dom = VirtualDom::new(|| {
let gen = 3 - generation() % 4;
let generation_count = 3 - generation() % 4;

rsx! {
div {
for i in 0..gen {
for i in 0..generation_count {
div { "{i}" }
}
}
Expand Down Expand Up @@ -231,11 +231,11 @@ fn list_shrink_multiroot() {
#[test]
fn removes_one_by_one_multiroot() {
let mut dom = VirtualDom::new(|| {
let gen = 3 - generation() % 4;
let generation_count = 3 - generation() % 4;

rsx! {
div {
{(0..gen).map(|i| rsx! {
{(0..generation_count).map(|i| rsx! {
div { "{i}" }
div { "{i}" }
})}
Expand Down
2 changes: 1 addition & 1 deletion packages/rsx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "dioxus-rsx"
version = { workspace = true }
authors = ["Jonathan Kelley", "Evan Almloff"]
edition = "2021"
edition = "2024"
license = "MIT OR Apache-2.0"
description = "Core functionality for Dioxus - a concurrent renderer-agnostic Virtual DOM for interactive user experiences"
repository = "https://github.com/DioxusLabs/dioxus/"
Expand Down
50 changes: 26 additions & 24 deletions packages/rsx/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ use super::literal::HotLiteral;
use crate::{innerlude::*, partial_closure::PartialClosure};

use proc_macro2::{Span, TokenStream as TokenStream2};
use quote::{quote, quote_spanned, ToTokens, TokenStreamExt};
use quote::{ToTokens, TokenStreamExt, quote, quote_spanned};
use std::fmt::Display;
use syn::{
Block, Expr, ExprBlock, ExprClosure, ExprIf, Ident, Lit, LitBool, LitFloat, LitInt, LitStr,
Stmt, Token,
ext::IdentExt,
parse::{Parse, ParseStream},
parse_quote,
spanned::Spanned,
Block, Expr, ExprBlock, ExprClosure, ExprIf, Ident, Lit, LitBool, LitFloat, LitInt, LitStr,
Stmt, Token,
};

/// A property value in the from of a `name: value` pair with an optional comma.
Expand Down Expand Up @@ -311,12 +311,10 @@ impl Attribute {
// Or if it is a builtin attribute with a single ident value
if let (AttributeName::BuiltIn(name), AttributeValue::AttrExpr(expr)) =
(&self.name, &self.value)
&& let Ok(Expr::Path(path)) = expr.as_expr()
&& path.path.get_ident() == Some(name)
{
if let Ok(Expr::Path(path)) = expr.as_expr() {
if path.path.get_ident() == Some(name) {
return true;
}
}
return true;
}

false
Expand Down Expand Up @@ -880,31 +878,35 @@ mod tests {
fn call_with_explicit_closure() {
let mut a: Attribute = parse2(quote! { onclick: |e| {} }).unwrap();
a.el_name = Some(parse_quote!(button));
assert!(a
.rendered_as_dynamic_attr()
.to_string()
.contains("call_with_explicit_closure"));
assert!(
a.rendered_as_dynamic_attr()
.to_string()
.contains("call_with_explicit_closure")
);

let mut a: Attribute = parse2(quote! { onclick: { let a = 1; |e| {} } }).unwrap();
a.el_name = Some(parse_quote!(button));
assert!(a
.rendered_as_dynamic_attr()
.to_string()
.contains("call_with_explicit_closure"));
assert!(
a.rendered_as_dynamic_attr()
.to_string()
.contains("call_with_explicit_closure")
);

let mut a: Attribute = parse2(quote! { onclick: { let b = 2; { |e| { b } } } }).unwrap();
a.el_name = Some(parse_quote!(button));
assert!(a
.rendered_as_dynamic_attr()
.to_string()
.contains("call_with_explicit_closure"));
assert!(
a.rendered_as_dynamic_attr()
.to_string()
.contains("call_with_explicit_closure")
);

let mut a: Attribute = parse2(quote! { onclick: { let r = |e| { b }; r } }).unwrap();
a.el_name = Some(parse_quote!(button));
assert!(!a
.rendered_as_dynamic_attr()
.to_string()
.contains("call_with_explicit_closure"));
assert!(
!a.rendered_as_dynamic_attr()
.to_string()
.contains("call_with_explicit_closure")
);
}

/// Make sure reserved keywords are parsed as attributes
Expand Down
Loading
Loading