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
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ uuid = { default-features = false, version = "1.18.0" }
bytes = { default-features = false, version = "1.10.1" }
http = { default-features = false, version = "1.3.1" }
regex = { default-features = false, version = "1.11.3" }
drain_filter_polyfill = { default-features = false, version = "0.1.3" }
tempfile = { default-features = false, version = "3.23.0" }
futures-lite = { default-features = false, version = "2.6.1" }
log = { default-features = false, version = "0.4.27" }
Expand Down
54 changes: 17 additions & 37 deletions leptos_macro/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,19 @@ impl Parse for Model {
.map(Prop::new)
.collect::<Vec<_>>();

// We need to remove the `#[doc = ""]` and `#[builder(_)]`
// attrs from the function signature
drain_filter(&mut item.attrs, |attr| match &attr.meta {
Meta::NameValue(attr) => attr.path == parse_quote!(doc),
Meta::List(attr) => attr.path == parse_quote!(prop),
_ => false,
});
const DISCARD_ATTRS: &[&str] = &["doc", "prop"];

let apply_discard = |attr: &syn::Attribute| {
!DISCARD_ATTRS
.iter()
.any(|discardable| attr.path().is_ident(discardable))
};

item.attrs.retain(apply_discard);

item.sig.inputs.iter_mut().for_each(|arg| {
if let FnArg::Typed(ty) = arg {
drain_filter(&mut ty.attrs, |attr| match &attr.meta {
Meta::NameValue(attr) => attr.path == parse_quote!(doc),
Meta::List(attr) => attr.path == parse_quote!(prop),
_ => false,
});
ty.attrs.retain(apply_discard);
}
});

Expand Down Expand Up @@ -113,22 +112,6 @@ fn maybe_modify_return_type(ret: &mut ReturnType) {
}
}

// implemented manually because Vec::drain_filter is nightly only
// follows std recommended parallel
pub fn drain_filter<T>(
vec: &mut Vec<T>,
mut some_predicate: impl FnMut(&mut T) -> bool,
) {
let mut i = 0;
while i < vec.len() {
if some_predicate(&mut vec[i]) {
_ = vec.remove(i);
} else {
i += 1;
}
}
}

pub fn convert_from_snake_case(name: &Ident) -> Ident {
let name_str = name.to_string();
if !name_str.is_case(Snake) {
Expand Down Expand Up @@ -668,15 +651,12 @@ pub struct DummyModel {
impl Parse for DummyModel {
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
let mut attrs = input.call(Attribute::parse_outer)?;
// Drop unknown attributes like #[deprecated]
drain_filter(&mut attrs, |attr| {
let path = attr.path();
!(path.is_ident("doc")
|| path.is_ident("allow")
|| path.is_ident("expect")
|| path.is_ident("warn")
|| path.is_ident("deny")
|| path.is_ident("forbid"))

const RETAIN_ATTRS: &[&str] =
&["doc", "allow", "expect", "warn", "deny", "forbid"];

attrs.retain(|attr| {
RETAIN_ATTRS.iter().any(|known| attr.path().is_ident(known))
});

let vis: Visibility = input.parse()?;
Expand Down
28 changes: 13 additions & 15 deletions leptos_macro/src/slot.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::component::{
convert_from_snake_case, drain_filter, is_option, unwrap_option, Docs,
convert_from_snake_case, is_option, unwrap_option, Docs,
};
use attribute_derive::FromAttr;
use proc_macro2::{Ident, TokenStream};
use quote::{quote, ToTokens, TokenStreamExt};
use syn::{
parse::Parse, parse_quote, Field, ItemStruct, LitStr, Meta, Type,
Visibility,
parse::Parse, parse_quote, Field, ItemStruct, LitStr, Type, Visibility,
};

pub struct Model {
Expand All @@ -30,19 +29,18 @@ impl Parse for Model {
.map(Prop::new)
.collect::<Vec<_>>();

// We need to remove the `#[doc = ""]` and `#[builder(_)]`
// attrs from the function signature
drain_filter(&mut item.attrs, |attr| match &attr.meta {
Meta::NameValue(attr) => attr.path == parse_quote!(doc),
Meta::List(attr) => attr.path == parse_quote!(prop),
_ => false,
});
const DISCARD_ATTRS: &[&str] = &["doc", "prop"];

let apply_discard = |attr: &syn::Attribute| {
!DISCARD_ATTRS
.iter()
.any(|discardable| attr.path().is_ident(discardable))
};

item.attrs.retain(apply_discard);

item.fields.iter_mut().for_each(|arg| {
drain_filter(&mut arg.attrs, |attr| match &attr.meta {
Meta::NameValue(attr) => attr.path == parse_quote!(doc),
Meta::List(attr) => attr.path == parse_quote!(prop),
_ => false,
});
arg.attrs.retain(apply_discard);
});

Ok(Self {
Expand Down
1 change: 0 additions & 1 deletion tachys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ web-sys = { features = [
"HtmlTemplateElement",
"HtmlOptionElement",
], workspace = true, default-features = true }
drain_filter_polyfill = { workspace = true, default-features = true }
indexmap = { workspace = true, default-features = true }
rustc-hash = { workspace = true, default-features = true }
futures = { workspace = true, default-features = true }
Expand Down
4 changes: 1 addition & 3 deletions tachys/src/view/keyed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::{
renderer::{CastFrom, Rndr},
ssr::StreamBuilder,
};
use drain_filter_polyfill::VecExt as VecDrainFilterExt;
use indexmap::IndexSet;
use rustc_hash::FxHasher;
use std::hash::{BuildHasherDefault, Hash};
Expand Down Expand Up @@ -762,8 +761,7 @@ fn apply_diff<T, VFS, V>(
children[at] = Some((set_index, item));
}

#[allow(unstable_name_collisions)]
children.drain_filter(|c| c.is_none());
children.retain(Option::is_some);
}

fn unpack_moves(diff: &Diff) -> (Vec<DiffOpMove>, Vec<DiffOpAdd>) {
Expand Down
Loading