Skip to content

Commit ed9e659

Browse files
committed
Fix nth of selectors in css modules
Fixes #883
1 parent 4cffb66 commit ed9e659

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

selectors/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ impl NthSelectorData {
13021302

13031303
/// Writes the beginning of the selector.
13041304
#[inline]
1305-
fn write_start<W: fmt::Write>(&self, dest: &mut W, is_function: bool) -> fmt::Result {
1305+
pub fn write_start<W: fmt::Write>(&self, dest: &mut W, is_function: bool) -> fmt::Result {
13061306
dest.write_str(match self.ty {
13071307
NthType::Child if is_function => ":nth-child(",
13081308
NthType::Child => ":first-child",
@@ -1322,7 +1322,7 @@ impl NthSelectorData {
13221322
/// Serialize <an+b> (part of the CSS Syntax spec, but currently only used here).
13231323
/// <https://drafts.csswg.org/css-syntax-3/#serialize-an-anb-value>
13241324
#[inline]
1325-
fn write_affine<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
1325+
pub fn write_affine<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
13261326
match (self.a, self.b) {
13271327
(0, 0) => dest.write_char('0'),
13281328

src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24993,6 +24993,27 @@ mod tests {
2499324993
Default::default(),
2499424994
true,
2499524995
);
24996+
24997+
css_modules_test(
24998+
":nth-child(1 of .foo) {width: 20px}",
24999+
":nth-child(1 of .EgL3uq_foo){width:20px}",
25000+
map! {
25001+
"foo" => "EgL3uq_foo"
25002+
},
25003+
HashMap::new(),
25004+
Default::default(),
25005+
true,
25006+
);
25007+
css_modules_test(
25008+
":nth-last-child(1 of .foo) {width: 20px}",
25009+
":nth-last-child(1 of .EgL3uq_foo){width:20px}",
25010+
map! {
25011+
"foo" => "EgL3uq_foo"
25012+
},
25013+
HashMap::new(),
25014+
Default::default(),
25015+
true,
25016+
);
2499625017
}
2499725018

2499825019
// Stable hashes between project roots.

src/selector.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,14 @@ where
16221622
selector.to_css(dest)?;
16231623
dest.write_char(')')
16241624
}
1625+
Component::NthOf(ref nth_of_data) => {
1626+
let nth_data = nth_of_data.nth_data();
1627+
nth_data.write_start(dest, true)?;
1628+
nth_data.write_affine(dest)?;
1629+
dest.write_str(" of ")?;
1630+
serialize_selector_list(nth_of_data.selectors().iter(), dest, context, true)?;
1631+
dest.write_char(')')
1632+
}
16251633
_ => {
16261634
cssparser::ToCss::to_css(component, dest)?;
16271635
Ok(())

0 commit comments

Comments
 (0)