Skip to content
Merged
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
8 changes: 0 additions & 8 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 packages/yew-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ rust-version = "1.64.0"
proc-macro = true

[dependencies]
boolinator = "2"
proc-macro-error = "1"
proc-macro2 = "1"
quote = "1"
Expand Down
5 changes: 3 additions & 2 deletions packages/yew-macro/src/html_tree/html_dashed_name.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::fmt;

use boolinator::Boolinator;
use proc_macro2::{Ident, Span, TokenStream};
use quote::{quote, ToTokens};
use syn::buffer::Cursor;
Expand Down Expand Up @@ -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;
Expand Down
33 changes: 20 additions & 13 deletions packages/yew-macro/src/html_tree/html_element.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -607,17 +608,21 @@ impl HtmlElementOpen {
impl PeekValue<TagKey> for HtmlElementOpen {
fn peek(cursor: Cursor) -> Option<TagKey> {
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 {
// Avoid parsing `<key=[...]>` as an element. It needs to be parsed as an `HtmlList`.
if name.to_string() == "key" {
let (punct, _) = cursor.punct()?;
// ... unless it isn't followed by a '='. `<key></key>` 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;
}
}

Expand Down Expand Up @@ -675,20 +680,22 @@ impl HtmlElementClose {
impl PeekValue<TagKey> for HtmlElementClose {
fn peek(cursor: Cursor) -> Option<TagKey> {
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)
}
}

Expand Down
3 changes: 1 addition & 2 deletions packages/yew-macro/src/html_tree/html_if.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use boolinator::Boolinator;
use proc_macro2::TokenStream;
use quote::{quote_spanned, ToTokens};
use syn::buffer::Cursor;
Expand All @@ -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(())
}
}

Expand Down
3 changes: 1 addition & 2 deletions packages/yew-macro/src/html_tree/html_iterable.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use boolinator::Boolinator;
use proc_macro2::TokenStream;
use quote::{quote_spanned, ToTokens};
use syn::buffer::Cursor;
Expand All @@ -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(())
}
}

Expand Down
19 changes: 12 additions & 7 deletions packages/yew-macro/src/html_tree/html_list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use boolinator::Boolinator;
use quote::{quote, quote_spanned, ToTokens};
use syn::buffer::Cursor;
use syn::parse::{Parse, ParseStream};
Expand Down Expand Up @@ -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(())
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion tools/website-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down