diff --git a/selectors/parser.rs b/selectors/parser.rs index 5f32ff79..d3e18f74 100644 --- a/selectors/parser.rs +++ b/selectors/parser.rs @@ -1302,7 +1302,7 @@ impl NthSelectorData { /// Writes the beginning of the selector. #[inline] - fn write_start(&self, dest: &mut W, is_function: bool) -> fmt::Result { + pub fn write_start(&self, dest: &mut W, is_function: bool) -> fmt::Result { dest.write_str(match self.ty { NthType::Child if is_function => ":nth-child(", NthType::Child => ":first-child", @@ -1322,7 +1322,7 @@ impl NthSelectorData { /// Serialize (part of the CSS Syntax spec, but currently only used here). /// #[inline] - fn write_affine(&self, dest: &mut W) -> fmt::Result { + pub fn write_affine(&self, dest: &mut W) -> fmt::Result { match (self.a, self.b) { (0, 0) => dest.write_char('0'), diff --git a/src/lib.rs b/src/lib.rs index 54e7260a..46ce5e39 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24993,6 +24993,27 @@ mod tests { Default::default(), true, ); + + css_modules_test( + ":nth-child(1 of .foo) {width: 20px}", + ":nth-child(1 of .EgL3uq_foo){width:20px}", + map! { + "foo" => "EgL3uq_foo" + }, + HashMap::new(), + Default::default(), + true, + ); + css_modules_test( + ":nth-last-child(1 of .foo) {width: 20px}", + ":nth-last-child(1 of .EgL3uq_foo){width:20px}", + map! { + "foo" => "EgL3uq_foo" + }, + HashMap::new(), + Default::default(), + true, + ); } // Stable hashes between project roots. diff --git a/src/selector.rs b/src/selector.rs index 86507b58..e624b199 100644 --- a/src/selector.rs +++ b/src/selector.rs @@ -1622,6 +1622,14 @@ where selector.to_css(dest)?; dest.write_char(')') } + Component::NthOf(ref nth_of_data) => { + let nth_data = nth_of_data.nth_data(); + nth_data.write_start(dest, true)?; + nth_data.write_affine(dest)?; + dest.write_str(" of ")?; + serialize_selector_list(nth_of_data.selectors().iter(), dest, context, true)?; + dest.write_char(')') + } _ => { cssparser::ToCss::to_css(component, dest)?; Ok(())