Skip to content

Commit 53968da

Browse files
committed
chore: Update cssparser & selectors
Signed-off-by: Dmitry Dygalo <[email protected]>
1 parent 7df132c commit 53968da

File tree

9 files changed

+38
-15
lines changed

9 files changed

+38
-15
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## [Unreleased]
44

5+
### Changed
6+
7+
- Update `cssparser` to `0.35`.
8+
- Update `selectors` to `0.28`.
9+
510
### Performance
611

712
- Slightly improve performance of HTML serialization.

css-inline/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ file = []
2929
stylesheet-cache = ["lru"]
3030

3131
[dependencies]
32-
cssparser = "0.31.2"
32+
cssparser = "0.35.0"
3333
html5ever = "0.27.0"
3434
indexmap = "2.1"
3535
lru = { version = "0.12.3", optional = true }
3636
pico-args = { version = "0.3", optional = true }
37+
precomputed-hash = "0.1.1"
3738
rayon = { version = "1.10", optional = true }
3839
reqwest = { version = "0.12.0", optional = true, default-features = false, features = ["rustls-tls", "blocking"] }
3940
rustc-hash = "2.0.0"
40-
selectors = "0.25.0"
41+
selectors = "0.28.0"
4142
smallvec = "1"
4243
url = "2"
4344

css-inline/src/html/document.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use super::{
99
};
1010
use crate::{html::DocumentStyleMap, InlineError};
1111
use html5ever::local_name;
12-
use selectors::NthIndexCache;
12+
use selectors::context::SelectorCaches;
1313
use std::{fmt, fmt::Formatter, io::Write, iter::successors};
1414

1515
/// HTML document representation.
@@ -297,7 +297,7 @@ impl Document {
297297
pub(crate) fn select<'a, 'b, 'c>(
298298
&'a self,
299299
selectors: &'b str,
300-
caches: &'c mut NthIndexCache,
300+
caches: &'c mut SelectorCaches,
301301
) -> Result<Select<'a, 'c>, ParseError<'b>> {
302302
select(self, selectors, caches)
303303
}

css-inline/src/html/element.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use super::{
77
use html5ever::{local_name, namespace_url, ns, Namespace, QualName};
88
use selectors::{
99
attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint},
10-
context::QuirksMode,
11-
matching, NthIndexCache, OpaqueElement,
10+
bloom::BloomFilter,
11+
context::{QuirksMode, SelectorCaches},
12+
matching, OpaqueElement,
1213
};
1314
use std::cmp::Ordering;
1415

@@ -92,14 +93,14 @@ impl<'a> Element<'a> {
9293
}
9394
}
9495
}
95-
pub(crate) fn matches(&self, selector: &Selector, cache: &mut NthIndexCache) -> bool {
96+
pub(crate) fn matches(&self, selector: &Selector, cache: &mut SelectorCaches) -> bool {
9697
let mut context = matching::MatchingContext::new(
9798
matching::MatchingMode::Normal,
9899
None,
99100
cache,
100101
QuirksMode::NoQuirks,
101102
matching::NeedsSelectorFlags::No,
102-
matching::IgnoreNthChildForInvalidation::No,
103+
matching::MatchingForInvalidation::No,
103104
);
104105
matching::matches_selector(selector, 0, None, self, &mut context)
105106
}
@@ -292,4 +293,10 @@ impl selectors::Element for Element<'_> {
292293
}
293294

294295
fn apply_selector_flags(&self, _: matching::ElementSelectorFlags) {}
296+
fn add_element_unique_hashes(&self, _: &mut BloomFilter) -> bool {
297+
false
298+
}
299+
fn has_custom_state(&self, _name: &LocalName) -> bool {
300+
false
301+
}
295302
}

css-inline/src/html/iter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use super::{
55
selectors::{ParseError, Selectors},
66
Specificity,
77
};
8-
use selectors::NthIndexCache;
8+
use selectors::context::SelectorCaches;
99

1010
/// Compile selectors from a string and create an element iterator that yields elements matching these selectors.
1111
#[inline]
1212
pub(crate) fn select<'a, 'b, 'c>(
1313
document: &'a Document,
1414
selectors: &'b str,
15-
caches: &'c mut NthIndexCache,
15+
caches: &'c mut SelectorCaches,
1616
) -> Result<Select<'a, 'c>, ParseError<'b>> {
1717
Selectors::compile(selectors).map(|selectors| Select {
1818
document,
@@ -25,7 +25,7 @@ pub(crate) fn select<'a, 'b, 'c>(
2525
/// An element iterator adaptor that yields elements matching given selectors.
2626
pub(crate) struct Select<'a, 'c> {
2727
document: &'a Document,
28-
caches: &'c mut NthIndexCache,
28+
caches: &'c mut SelectorCaches,
2929
iter: std::slice::Iter<'a, NodeId>,
3030
/// The selectors to be matched.
3131
selectors: Selectors,

css-inline/src/html/selectors/local_name.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use cssparser::ToCss;
2+
use precomputed_hash::PrecomputedHash;
23
use std::fmt::Write;
34

45
/// `LocalName` type wraps `html5ever::LocalName` to extend it by implementing the `ToCss` trait,
@@ -37,3 +38,9 @@ impl ToCss for LocalName {
3738
dest.write_str(self.0.as_ref())
3839
}
3940
}
41+
42+
impl PrecomputedHash for LocalName {
43+
fn precomputed_hash(&self) -> u32 {
44+
self.0.precomputed_hash()
45+
}
46+
}

css-inline/src/html/selectors/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl Selectors {
4949
/// Compile a list of selectors.
5050
#[inline]
5151
pub(super) fn compile(selectors: &str) -> Result<Selectors, ParseError<'_>> {
52-
parse(selectors).map(|list| Selectors(list.0))
52+
parse(selectors).map(|list| Selectors(list.slice().into()))
5353
}
5454

5555
/// Iterator over selectors.

css-inline/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub use error::InlineError;
3737
use indexmap::IndexMap;
3838
#[cfg(feature = "stylesheet-cache")]
3939
use lru::{DefaultHasher, LruCache};
40-
use selectors::NthIndexCache;
40+
use selectors::context::SelectorCaches;
4141
use std::{borrow::Cow, fmt::Formatter, hash::BuildHasherDefault, io::Write, sync::Arc};
4242

4343
use crate::html::ElementStyleMap;
@@ -441,7 +441,7 @@ impl<'a> CSSInliner<'a> {
441441
rule_list.push(rule);
442442
}
443443
// This cache is unused but required in the `selectors` API
444-
let mut caches = NthIndexCache::default();
444+
let mut caches = SelectorCaches::default();
445445
for (selectors, (start, end)) in &rule_list {
446446
// Only CSS Syntax Level 3 is supported, therefore it is OK to split by `,`
447447
// With `is` or `where` selectors (Level 4) this split should be done on the parser level

css-inline/src/parser.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use cssparser::ParserState;
2+
13
pub(crate) struct CSSRuleListParser<'d, 'i>(&'d mut Vec<Declaration<'i>>);
24

35
impl<'d, 'i> CSSRuleListParser<'d, 'i> {
@@ -38,7 +40,7 @@ impl<'i> cssparser::QualifiedRuleParser<'i> for CSSRuleListParser<'_, 'i> {
3840
fn parse_block<'t>(
3941
&mut self,
4042
prelude: Self::Prelude,
41-
_: &cssparser::ParserState,
43+
_: &ParserState,
4244
input: &mut cssparser::Parser<'i, 't>,
4345
) -> Result<Self::QualifiedRule, cssparser::ParseError<'i, Self::Error>> {
4446
// Parse list of declarations
@@ -61,6 +63,7 @@ impl<'i> cssparser::DeclarationParser<'i> for CSSDeclarationListParser {
6163
&mut self,
6264
name: Name<'i>,
6365
input: &mut cssparser::Parser<'i, 't>,
66+
_declaration_start: &ParserState,
6467
) -> Result<Self::Declaration, cssparser::ParseError<'i, Self::Error>> {
6568
Ok((name, exhaust(input)))
6669
}

0 commit comments

Comments
 (0)