Skip to content

Commit 2191176

Browse files
antonok-edmkornelski
authored andcommitted
update cssparser to v0.28 and selectors to v0.23
1 parent 7952f29 commit 2191176

File tree

4 files changed

+45
-40
lines changed

4 files changed

+45
-40
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ name = "bench"
3434
[dependencies]
3535
bitflags = "2.0.0"
3636
cfg-if = "1.0.0"
37-
cssparser = "0.27.2"
37+
cssparser = "0.28.1"
3838
encoding_rs = "0.8.13"
3939
lazycell = "1.3.0"
4040
lazy_static = "1.3.0"
4141
memchr = "2.1.2"
42-
selectors = "0.22.0"
42+
selectors = "0.23.0"
4343
thiserror = "1.0.2"
4444
hashbrown = "0.15.0"
4545
mime = "0.3.16"

src/selectors_vm/ast.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ impl From<&Component<SelectorImplDescriptor>> for Condition {
123123
#[inline]
124124
fn from(component: &Component<SelectorImplDescriptor>) -> Self {
125125
match component {
126-
Component::LocalName(n) => Self::OnTagName(OnTagNameExpr::LocalName(n.name.clone())),
126+
Component::LocalName(n) => Self::OnTagName(OnTagNameExpr::LocalName(n.name.0.clone())),
127127
Component::ExplicitUniversalType | Component::ExplicitAnyNamespace => {
128128
Self::OnTagName(OnTagNameExpr::ExplicitAny)
129129
}
130130
Component::ExplicitNoNamespace => Self::OnTagName(OnTagNameExpr::Unmatchable),
131-
Component::ID(id) => Self::OnAttributes(OnAttributesExpr::Id(id.to_owned())),
132-
Component::Class(c) => Self::OnAttributes(OnAttributesExpr::Class(c.to_owned())),
131+
Component::ID(id) => Self::OnAttributes(OnAttributesExpr::Id(id.0.to_owned())),
132+
Component::Class(c) => Self::OnAttributes(OnAttributesExpr::Class(c.0.to_owned())),
133133
Component::AttributeInNoNamespaceExists { local_name, .. } => {
134-
Self::OnAttributes(OnAttributesExpr::AttributeExists(local_name.to_owned()))
134+
Self::OnAttributes(OnAttributesExpr::AttributeExists(local_name.0.to_owned()))
135135
}
136136
&Component::AttributeInNoNamespace {
137137
ref local_name,
@@ -145,8 +145,8 @@ impl From<&Component<SelectorImplDescriptor>> for Condition {
145145
} else {
146146
Self::OnAttributes(OnAttributesExpr::AttributeComparisonExpr(
147147
AttributeComparisonExpr::new(
148-
local_name.to_owned(),
149-
value.to_owned(),
148+
local_name.0.to_owned(),
149+
value.0.to_owned(),
150150
case_sensitivity,
151151
operator,
152152
),
@@ -304,8 +304,9 @@ where
304304
"Unsupported selector components should be filtered out by the parser."
305305
),
306306
},
307-
Component::Negation(c) => {
308-
c.iter().for_each(|c| predicate.add_component(c, true));
307+
Component::Negation(ss) => {
308+
ss.iter()
309+
.for_each(|s| s.iter().for_each(|c| predicate.add_component(c, true)));
309310
}
310311
_ => predicate.add_component(component, false),
311312
}
@@ -820,10 +821,9 @@ mod tests {
820821
r#"div[foo~"bar"]"#,
821822
SelectorError::UnexpectedTokenInAttribute,
822823
);
823-
assert_err(":not(:not(p))", SelectorError::NestedNegation);
824824
assert_err("svg|img", SelectorError::NamespacedSelector);
825825
assert_err(".foo()", SelectorError::InvalidClassName);
826-
assert_err(":not()", SelectorError::EmptyNegation);
826+
assert_err(":not()", SelectorError::EmptySelector);
827827
assert_err("div + span", SelectorError::UnsupportedCombinator('+'));
828828
assert_err("div ~ span", SelectorError::UnsupportedCombinator('~'));
829829
}

src/selectors_vm/error.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ pub enum SelectorError {
4545
#[error("Invalid or unescaped class name in selector.")]
4646
InvalidClassName,
4747

48-
/// An empty negation in the selector.
49-
#[error("Empty negation in selector.")]
50-
EmptyNegation,
51-
5248
/// Unsupported combinator in the selector.
5349
#[error("Unsupported combinator `{0}` in selector.")]
5450
UnsupportedCombinator(char),
@@ -80,23 +76,20 @@ impl From<SelectorParseError<'_>> for SelectorError {
8076
SelectorParseErrorKind::EmptySelector => Self::EmptySelector,
8177
SelectorParseErrorKind::DanglingCombinator => Self::DanglingCombinator,
8278
SelectorParseErrorKind::UnsupportedPseudoClassOrElement(_)
83-
| SelectorParseErrorKind::PseudoElementInComplexSelector
79+
| SelectorParseErrorKind::InvalidPseudoElementInsideWhere
8480
| SelectorParseErrorKind::NonPseudoElementAfterSlotted
8581
| SelectorParseErrorKind::InvalidPseudoElementAfterSlotted
8682
| SelectorParseErrorKind::PseudoElementExpectedColon(_)
8783
| SelectorParseErrorKind::PseudoElementExpectedIdent(_)
8884
| SelectorParseErrorKind::NoIdentForPseudo(_)
8985
// NOTE: according to the parser code this error occures only during
9086
// the parsing of vendor-specific pseudo-classes.
91-
| SelectorParseErrorKind::NonCompoundSelector
92-
// NOTE: according to the parser code this error occures only during
93-
// the parsing of the :slotted() pseudo-class.
94-
| SelectorParseErrorKind::NonSimpleSelectorInNegation => {
87+
| SelectorParseErrorKind::NonCompoundSelector => {
9588
Self::UnsupportedPseudoClassOrElement
9689
}
97-
// NOTE: this is currently the only case in the parser code
98-
// that triggers this error.
99-
SelectorParseErrorKind::UnexpectedIdent(_) => Self::NestedNegation,
90+
// NOTE: there are currently no cases in the parser code
91+
// that trigger this error.
92+
SelectorParseErrorKind::UnexpectedIdent(_) => unreachable!(),
10093
SelectorParseErrorKind::ExpectedNamespace(_) => Self::NamespacedSelector,
10194
SelectorParseErrorKind::ExplicitNamespaceUnexpectedToken(_) => {
10295
Self::UnexpectedToken
@@ -108,7 +101,6 @@ impl From<SelectorParseError<'_>> for SelectorError {
108101
Self::UnexpectedTokenInAttribute
109102
}
110103
SelectorParseErrorKind::ClassNeedsIdent(_) => Self::InvalidClassName,
111-
SelectorParseErrorKind::EmptyNegation => Self::EmptyNegation,
112104
SelectorParseErrorKind::InvalidState => panic!("invalid state"),
113105
},
114106
}

src/selectors_vm/parser.rs

+28-15
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,32 @@ use std::str::FromStr;
1111
#[derive(Debug, Clone, Eq, PartialEq)]
1212
pub(crate) struct SelectorImplDescriptor;
1313

14+
#[derive(Clone, Default, Eq, PartialEq)]
15+
pub struct CssString(pub String);
16+
17+
impl<'a> From<&'a str> for CssString {
18+
fn from(value: &'a str) -> Self {
19+
Self(value.to_string())
20+
}
21+
}
22+
23+
impl ToCss for CssString {
24+
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
25+
where
26+
W: fmt::Write,
27+
{
28+
write!(dest, "{}", self.0)
29+
}
30+
}
31+
1432
impl SelectorImpl for SelectorImplDescriptor {
15-
type AttrValue = String;
16-
type Identifier = String;
17-
type ClassName = String;
18-
type PartName = String;
19-
type LocalName = String;
20-
type NamespacePrefix = String;
33+
type AttrValue = CssString;
34+
type Identifier = CssString;
35+
type LocalName = CssString;
36+
type NamespacePrefix = CssString;
2137
type NamespaceUrl = Namespace;
2238
type BorrowedNamespaceUrl = Namespace;
23-
type BorrowedLocalName = String;
39+
type BorrowedLocalName = CssString;
2440

2541
type NonTSPseudoClass = NonTSPseudoClassStub;
2642
type PseudoElement = PseudoElementStub;
@@ -57,11 +73,6 @@ impl NonTSPseudoClass for NonTSPseudoClassStub {
5773
#[allow(clippy::uninhabited_references)]
5874
match *self {}
5975
}
60-
61-
fn has_zero_specificity(&self) -> bool {
62-
#[allow(clippy::uninhabited_references)]
63-
match *self {}
64-
}
6576
}
6677

6778
impl ToCss for NonTSPseudoClassStub {
@@ -110,14 +121,15 @@ impl SelectorsParser {
110121
| Component::AttributeInNoNamespaceExists { .. }
111122
| Component::AttributeInNoNamespace { .. } => Ok(()),
112123

113-
Component::Negation(components) => {
114-
components.iter().try_for_each(Self::validate_component)
115-
}
124+
Component::Negation(selectors) => selectors
125+
.iter()
126+
.try_for_each(|s| s.iter().try_for_each(Self::validate_component)),
116127

117128
// Unsupported
118129
Component::Empty
119130
| Component::Part(_)
120131
| Component::Host(_)
132+
| Component::Is(_)
121133
| Component::LastChild
122134
| Component::LastOfType
123135
| Component::NthLastChild(_, _)
@@ -126,6 +138,7 @@ impl SelectorsParser {
126138
| Component::OnlyOfType
127139
| Component::Root
128140
| Component::Scope
141+
| Component::Where(_)
129142
| Component::PseudoElement(_)
130143
| Component::NonTSPseudoClass(_)
131144
| Component::Slotted(_) => Err(SelectorError::UnsupportedPseudoClassOrElement),

0 commit comments

Comments
 (0)