diff --git a/selectors/builder.rs b/selectors/builder.rs index 08cd9711..6bcad0d9 100644 --- a/selectors/builder.rs +++ b/selectors/builder.rs @@ -305,6 +305,8 @@ where | Component::Scope | Component::NthChild(..) | Component::NthLastChild(..) + | Component::NthCol(..) + | Component::NthLastCol(..) | Component::NthOfType(..) | Component::NthLastOfType(..) | Component::FirstOfType diff --git a/selectors/matching.rs b/selectors/matching.rs index e51e33a7..fac74174 100644 --- a/selectors/matching.rs +++ b/selectors/matching.rs @@ -372,6 +372,8 @@ fn matches_hover_and_active_quirk<'i, Impl: SelectorImpl<'i>>( | Component::Empty | Component::NthChild(_, _) | Component::NthLastChild(_, _) + | Component::NthCol(_, _) + | Component::NthLastCol(_, _) | Component::NthOfType(_, _) | Component::NthLastOfType(_, _) | Component::FirstOfType @@ -787,6 +789,8 @@ where }, Component::NthChild(a, b) => matches_generic_nth_child(element, context, a, b, false, false, flags_setter), Component::NthLastChild(a, b) => matches_generic_nth_child(element, context, a, b, false, true, flags_setter), + Component::NthCol(a, b) => matches_generic_nth_child(element, context, a, b, false, false, flags_setter), + Component::NthLastCol(a, b) => matches_generic_nth_child(element, context, a, b, false, true, flags_setter), Component::NthOfType(a, b) => matches_generic_nth_child(element, context, a, b, true, false, flags_setter), Component::NthLastOfType(a, b) => matches_generic_nth_child(element, context, a, b, true, true, flags_setter), Component::FirstOfType => matches_generic_nth_child(element, context, 0, 1, true, false, flags_setter), diff --git a/selectors/parser.rs b/selectors/parser.rs index 396461e4..6f64a31f 100644 --- a/selectors/parser.rs +++ b/selectors/parser.rs @@ -1107,6 +1107,8 @@ pub enum Component<'i, Impl: SelectorImpl<'i>> { Scope, NthChild(i32, i32), NthLastChild(i32, i32), + NthCol(i32, i32), // https://www.w3.org/TR/selectors-4/#the-nth-col-pseudo + NthLastCol(i32, i32), // https://www.w3.org/TR/selectors-4/#the-nth-last-col-pseudo NthOfType(i32, i32), NthLastOfType(i32, i32), FirstOfType, @@ -1604,10 +1606,12 @@ impl<'i, Impl: SelectorImpl<'i>> ToCss for Component<'i, Impl> { FirstOfType => dest.write_str(":first-of-type"), LastOfType => dest.write_str(":last-of-type"), OnlyOfType => dest.write_str(":only-of-type"), - NthChild(a, b) | NthLastChild(a, b) | NthOfType(a, b) | NthLastOfType(a, b) => { + NthChild(a, b) | NthLastChild(a, b) | NthOfType(a, b) | NthLastOfType(a, b) | NthCol(a, b) | NthLastCol(a, b) => { match *self { NthChild(_, _) => dest.write_str(":nth-child(")?, NthLastChild(_, _) => dest.write_str(":nth-last-child(")?, + NthCol(_, _) => dest.write_str(":nth-col(")?, + NthLastCol(_, _) => dest.write_str(":nth-last-col(")?, NthOfType(_, _) => dest.write_str(":nth-of-type(")?, NthLastOfType(_, _) => dest.write_str(":nth-last-of-type(")?, _ => unreachable!(), @@ -2381,8 +2385,10 @@ where { match_ignore_ascii_case! { &name, "nth-child" => return parse_nth_pseudo_class(parser, input, *state, Component::NthChild), - "nth-of-type" => return parse_nth_pseudo_class(parser, input, *state, Component::NthOfType), "nth-last-child" => return parse_nth_pseudo_class(parser, input, *state, Component::NthLastChild), + "nth-col" => return parse_nth_pseudo_class(parser, input, *state, Component::NthCol), + "nth-last-col" => return parse_nth_pseudo_class(parser, input, *state, Component::NthLastCol), + "nth-of-type" => return parse_nth_pseudo_class(parser, input, *state, Component::NthOfType), "nth-last-of-type" => return parse_nth_pseudo_class(parser, input, *state, Component::NthLastOfType), "is" if parser.parse_is_and_where() => return parse_is_or_where(parser, input, state, Component::Is), "where" if parser.parse_is_and_where() => return parse_is_or_where(parser, input, state, Component::Where), diff --git a/src/lib.rs b/src/lib.rs index 9634848d..53e7f7e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5228,6 +5228,17 @@ mod tests { #[test] fn test_selectors() { + minify_test(":nth-col(2n) {width: 20px}", ":nth-col(2n){width:20px}"); + minify_test(":nth-col(10n-1) {width: 20px}", ":nth-col(10n-1){width:20px}"); + minify_test(":nth-col(-n+2) {width: 20px}", ":nth-col(-n+2){width:20px}"); + minify_test(":nth-col(even) {width: 20px}", ":nth-col(2n){width:20px}"); + minify_test(":nth-col(odd) {width: 20px}", ":nth-col(2n+1){width:20px}"); + minify_test(":nth-last-col(2n) {width: 20px}", ":nth-last-col(2n){width:20px}"); + minify_test(":nth-last-col(10n-1) {width: 20px}", ":nth-last-col(10n-1){width:20px}"); + minify_test(":nth-last-col(-n+2) {width: 20px}", ":nth-last-col(-n+2){width:20px}"); + minify_test(":nth-last-col(even) {width: 20px}", ":nth-last-col(2n){width:20px}"); + minify_test(":nth-last-col(odd) {width: 20px}", ":nth-last-col(2n+1){width:20px}"); + minify_test("[foo=\"baz\"] {color:red}", "[foo=baz]{color:red}"); minify_test("[foo=\"foo bar\"] {color:red}", "[foo=foo\\ bar]{color:red}"); minify_test("[foo=\"foo bar baz\"] {color:red}", "[foo=\"foo bar baz\"]{color:red}"); diff --git a/src/selector.rs b/src/selector.rs index fa3c5155..2f414d19 100644 --- a/src/selector.rs +++ b/src/selector.rs @@ -1385,6 +1385,8 @@ pub fn is_compatible(selectors: &SelectorList, targets: Option