From 753bafefdd2e8ef6c18ffc81fe216617c82c093b Mon Sep 17 00:00:00 2001 From: Tim Kurdov Date: Fri, 29 Sep 2023 12:33:24 +0100 Subject: [PATCH] Remove the dependency on `boolinator` (#3420) * removed boolinator from dependencies of yew-macro * removed boolinator from the dependencies of tools/website-test * fixed formatting * removed a lint fix --- Cargo.lock | 8 ----- packages/yew-macro/Cargo.toml | 1 - .../src/html_tree/html_dashed_name.rs | 5 +-- .../yew-macro/src/html_tree/html_element.rs | 33 +++++++++++-------- packages/yew-macro/src/html_tree/html_if.rs | 3 +- .../yew-macro/src/html_tree/html_iterable.rs | 3 +- packages/yew-macro/src/html_tree/html_list.rs | 19 +++++++---- tools/website-test/Cargo.toml | 1 - 8 files changed, 37 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f7ff3ab5..270eb0cfa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -313,12 +313,6 @@ dependencies = [ "yew", ] -[[package]] -name = "boolinator" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfa8873f51c92e232f9bac4065cddef41b714152812bfc5f7672ba16d6ef8cd9" - [[package]] name = "bumpalo" version = "3.13.0" @@ -3467,7 +3461,6 @@ dependencies = [ name = "website-test" version = "0.1.0" dependencies = [ - "boolinator", "derive_more", "glob", "gloo 0.10.0", @@ -3744,7 +3737,6 @@ dependencies = [ name = "yew-macro" version = "0.21.0" dependencies = [ - "boolinator", "once_cell", "prettyplease", "proc-macro-error", diff --git a/packages/yew-macro/Cargo.toml b/packages/yew-macro/Cargo.toml index 97c2204b1..9d497486b 100644 --- a/packages/yew-macro/Cargo.toml +++ b/packages/yew-macro/Cargo.toml @@ -16,7 +16,6 @@ rust-version = "1.64.0" proc-macro = true [dependencies] -boolinator = "2" proc-macro-error = "1" proc-macro2 = "1" quote = "1" diff --git a/packages/yew-macro/src/html_tree/html_dashed_name.rs b/packages/yew-macro/src/html_tree/html_dashed_name.rs index 6699b779f..ca7fe733b 100644 --- a/packages/yew-macro/src/html_tree/html_dashed_name.rs +++ b/packages/yew-macro/src/html_tree/html_dashed_name.rs @@ -1,6 +1,5 @@ use std::fmt; -use boolinator::Boolinator; use proc_macro2::{Ident, Span, TokenStream}; use quote::{quote, ToTokens}; use syn::buffer::Cursor; @@ -54,7 +53,9 @@ impl fmt::Display for HtmlDashedName { impl Peek<'_, Self> for HtmlDashedName { fn peek(cursor: Cursor) -> Option<(Self, Cursor)> { let (name, cursor) = cursor.ident()?; - non_capitalized_ascii(&name.to_string()).as_option()?; + if !non_capitalized_ascii(&name.to_string()) { + return None; + } let mut extended = Vec::new(); let mut cursor = cursor; diff --git a/packages/yew-macro/src/html_tree/html_element.rs b/packages/yew-macro/src/html_tree/html_element.rs index 19d814ed4..0124dd0c0 100644 --- a/packages/yew-macro/src/html_tree/html_element.rs +++ b/packages/yew-macro/src/html_tree/html_element.rs @@ -1,4 +1,3 @@ -use boolinator::Boolinator; use proc_macro2::{Delimiter, Span, TokenStream}; use proc_macro_error::emit_warning; use quote::{quote, quote_spanned, ToTokens}; @@ -507,7 +506,9 @@ pub struct DynamicName { impl Peek<'_, ()> for DynamicName { fn peek(cursor: Cursor) -> Option<((), Cursor)> { let (punct, cursor) = cursor.punct()?; - (punct.as_char() == '@').as_option()?; + if punct.as_char() != '@' { + return None; + } // move cursor past block if there is one let cursor = cursor @@ -607,7 +608,9 @@ impl HtmlElementOpen { impl PeekValue for HtmlElementOpen { fn peek(cursor: Cursor) -> Option { let (punct, cursor) = cursor.punct()?; - (punct.as_char() == '<').as_option()?; + if punct.as_char() != '<' { + return None; + } let (tag_key, cursor) = TagName::peek(cursor)?; if let TagKey::Lit(name) = &tag_key { @@ -615,9 +618,11 @@ impl PeekValue for HtmlElementOpen { if name.to_string() == "key" { let (punct, _) = cursor.punct()?; // ... unless it isn't followed by a '='. `` is a valid element! - (punct.as_char() != '=').as_option()?; - } else { - non_capitalized_ascii(&name.to_string()).as_option()?; + if punct.as_char() == '=' { + return None; + } + } else if !non_capitalized_ascii(&name.to_string()) { + return None; } } @@ -675,20 +680,22 @@ impl HtmlElementClose { impl PeekValue for HtmlElementClose { fn peek(cursor: Cursor) -> Option { let (punct, cursor) = cursor.punct()?; - (punct.as_char() == '<').as_option()?; + if punct.as_char() != '<' { + return None; + } let (punct, cursor) = cursor.punct()?; - (punct.as_char() == '/').as_option()?; + if punct.as_char() != '/' { + return None; + } let (tag_key, cursor) = TagName::peek(cursor)?; - if let TagKey::Lit(name) = &tag_key { - non_capitalized_ascii(&name.to_string()).as_option()?; + if matches!(&tag_key, TagKey::Lit(name) if !non_capitalized_ascii(&name.to_string())) { + return None; } let (punct, _) = cursor.punct()?; - (punct.as_char() == '>').as_option()?; - - Some(tag_key) + (punct.as_char() == '>').then_some(tag_key) } } diff --git a/packages/yew-macro/src/html_tree/html_if.rs b/packages/yew-macro/src/html_tree/html_if.rs index 82793aba4..8b5481fc2 100644 --- a/packages/yew-macro/src/html_tree/html_if.rs +++ b/packages/yew-macro/src/html_tree/html_if.rs @@ -1,4 +1,3 @@ -use boolinator::Boolinator; use proc_macro2::TokenStream; use quote::{quote_spanned, ToTokens}; use syn::buffer::Cursor; @@ -19,7 +18,7 @@ pub struct HtmlIf { impl PeekValue<()> for HtmlIf { fn peek(cursor: Cursor) -> Option<()> { let (ident, _) = cursor.ident()?; - (ident == "if").as_option() + (ident == "if").then_some(()) } } diff --git a/packages/yew-macro/src/html_tree/html_iterable.rs b/packages/yew-macro/src/html_tree/html_iterable.rs index 33d333378..0f44b3298 100644 --- a/packages/yew-macro/src/html_tree/html_iterable.rs +++ b/packages/yew-macro/src/html_tree/html_iterable.rs @@ -1,4 +1,3 @@ -use boolinator::Boolinator; use proc_macro2::TokenStream; use quote::{quote_spanned, ToTokens}; use syn::buffer::Cursor; @@ -14,7 +13,7 @@ pub struct HtmlIterable(Expr); impl PeekValue<()> for HtmlIterable { fn peek(cursor: Cursor) -> Option<()> { let (ident, _) = cursor.ident()?; - (ident == "for").as_option() + (ident == "for").then_some(()) } } diff --git a/packages/yew-macro/src/html_tree/html_list.rs b/packages/yew-macro/src/html_tree/html_list.rs index c9ee3933c..e48f250bf 100644 --- a/packages/yew-macro/src/html_tree/html_list.rs +++ b/packages/yew-macro/src/html_tree/html_list.rs @@ -1,4 +1,3 @@ -use boolinator::Boolinator; use quote::{quote, quote_spanned, ToTokens}; use syn::buffer::Cursor; use syn::parse::{Parse, ParseStream}; @@ -99,14 +98,16 @@ impl HtmlListOpen { impl PeekValue<()> for HtmlListOpen { fn peek(cursor: Cursor) -> Option<()> { let (punct, cursor) = cursor.punct()?; - (punct.as_char() == '<').as_option()?; + if punct.as_char() != '<' { + return None; + } // make sure it's either a property (key=value) or it's immediately closed if let Some((_, cursor)) = HtmlDashedName::peek(cursor) { let (punct, _) = cursor.punct()?; - (punct.as_char() == '=' || punct.as_char() == '?').as_option() + (punct.as_char() == '=' || punct.as_char() == '?').then_some(()) } else { let (punct, _) = cursor.punct()?; - (punct.as_char() == '>').as_option() + (punct.as_char() == '>').then_some(()) } } } @@ -156,12 +157,16 @@ impl HtmlListClose { impl PeekValue<()> for HtmlListClose { fn peek(cursor: Cursor) -> Option<()> { let (punct, cursor) = cursor.punct()?; - (punct.as_char() == '<').as_option()?; + if punct.as_char() != '<' { + return None; + } let (punct, cursor) = cursor.punct()?; - (punct.as_char() == '/').as_option()?; + if punct.as_char() != '/' { + return None; + } let (punct, _) = cursor.punct()?; - (punct.as_char() == '>').as_option() + (punct.as_char() == '>').then_some(()) } } impl Parse for HtmlListClose { diff --git a/tools/website-test/Cargo.toml b/tools/website-test/Cargo.toml index ca0233f99..a380cd928 100644 --- a/tools/website-test/Cargo.toml +++ b/tools/website-test/Cargo.toml @@ -10,7 +10,6 @@ rust-version = "1.62" yew-agent = { path = "../../packages/yew-agent/" } [dev-dependencies] -boolinator = "2.4" derive_more = "0.99" gloo = "0.10" js-sys = "0.3"