:is is alias for :matches
This commit is contained in:
parent
2b72a1fc0d
commit
5c61f8ccaa
@ -656,13 +656,14 @@ impl Extender {
|
||||
// become `.foo:not(.bar)`. However, this is a narrow edge case and
|
||||
// supporting it properly would make this code and the code calling it
|
||||
// a lot more complicated, so it's not supported for now.
|
||||
if inner_pseudo.normalized_name() == "matches" {
|
||||
let inner_pseudo_normalized = inner_pseudo.normalized_name();
|
||||
if inner_pseudo_normalized == "matches" || inner_pseudo_normalized == "is" {
|
||||
inner_pseudo.selector.clone().unwrap().components
|
||||
} else {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
"matches" | "any" | "current" | "nth-child" | "nth-last-child" => {
|
||||
"matches" | "is" | "any" | "current" | "nth-child" | "nth-last-child" => {
|
||||
// As above, we could theoretically support :not within :matches, but
|
||||
// doing so would require this method and its callers to handle much
|
||||
// more complex cases that likely aren't worth the pain.
|
||||
|
@ -36,9 +36,10 @@ impl DevouredWhitespace {
|
||||
}
|
||||
|
||||
/// Pseudo-class selectors that take unadorned selectors as arguments.
|
||||
const SELECTOR_PSEUDO_CLASSES: [&str; 7] = [
|
||||
const SELECTOR_PSEUDO_CLASSES: [&str; 8] = [
|
||||
"not",
|
||||
"matches",
|
||||
"is",
|
||||
"current",
|
||||
"any",
|
||||
"has",
|
||||
|
@ -12,7 +12,7 @@ use super::{
|
||||
QualifiedName, SelectorList, Specificity,
|
||||
};
|
||||
|
||||
const SUBSELECTOR_PSEUDOS: [&str; 4] = ["matches", "any", "nth-child", "nth-last-child"];
|
||||
const SUBSELECTOR_PSEUDOS: [&str; 5] = ["matches", "is", "any", "nth-child", "nth-last-child"];
|
||||
|
||||
const BASE_SPECIFICITY: i32 = 1000;
|
||||
|
||||
@ -487,7 +487,7 @@ impl Pseudo {
|
||||
) -> bool {
|
||||
debug_assert!(self.selector.is_some());
|
||||
match self.normalized_name() {
|
||||
"matches" | "any" => {
|
||||
"matches" | "is" | "any" => {
|
||||
let pseudos = selector_pseudos_named(compound.clone(), &self.name, true);
|
||||
pseudos.iter().any(move |pseudo2| {
|
||||
self.selector
|
||||
|
@ -296,6 +296,21 @@ test!(
|
||||
"a {\n color: selector-extend(\":not(.c)\", \".c\", \".d:matches(.e, .f)\");\n}\n",
|
||||
"a {\n color: :not(.c):not(.d:matches(.e, .f));\n}\n"
|
||||
);
|
||||
test!(
|
||||
simple_pseudo_idempotent_not_and_is_list,
|
||||
"a {\n color: selector-extend(\":not(.c)\", \".c\", \":is(.d, .e)\");\n}\n",
|
||||
"a {\n color: :not(.c):not(.d):not(.e);\n}\n"
|
||||
);
|
||||
test!(
|
||||
simple_pseudo_idempotent_not_and_is_list_of_complex,
|
||||
"a {\n color: selector-extend(\":not(.c)\", \".c\", \":is(.d .e, .f .g)\");\n}\n",
|
||||
"a {\n color: :not(.c):not(.d .e):not(.f .g);\n}\n"
|
||||
);
|
||||
test!(
|
||||
simple_pseudo_idempotent_not_and_is_in_compound,
|
||||
"a {\n color: selector-extend(\":not(.c)\", \".c\", \".d:is(.e, .f)\");\n}\n",
|
||||
"a {\n color: :not(.c):not(.d:is(.e, .f));\n}\n"
|
||||
);
|
||||
test!(
|
||||
simple_pseudo_idempotent_not_and_not_in_extender,
|
||||
"a {\n color: selector-extend(\":not(.c)\", \".c\", \":not(.d)\");\n}\n",
|
||||
|
@ -37,15 +37,25 @@ test!(
|
||||
"a {\n color: e c d.f;\n}\n"
|
||||
);
|
||||
test!(
|
||||
nest_parent_in_special_pseudo,
|
||||
nest_parent_in_special_pseudo_matches,
|
||||
"a {\n color: selector-nest(\"c\", \":matches(&)\");\n}\n",
|
||||
"a {\n color: :matches(c);\n}\n"
|
||||
);
|
||||
test!(
|
||||
nest_complex_super_parent_in_special_pseudo,
|
||||
nest_complex_super_parent_in_special_pseudo_matches,
|
||||
"a {\n color: selector-nest(\"c d\", \":matches(&)\");\n}\n",
|
||||
"a {\n color: :matches(c d);\n}\n"
|
||||
);
|
||||
test!(
|
||||
nest_parent_in_special_pseudo_is,
|
||||
"a {\n color: selector-nest(\"c\", \":is(&)\");\n}\n",
|
||||
"a {\n color: :is(c);\n}\n"
|
||||
);
|
||||
test!(
|
||||
nest_complex_super_parent_in_special_pseudo_is,
|
||||
"a {\n color: selector-nest(\"c d\", \":is(&)\");\n}\n",
|
||||
"a {\n color: :is(c d);\n}\n"
|
||||
);
|
||||
test!(
|
||||
nest_multiple_parent,
|
||||
"a {\n color: selector-nest(\"c\", \"&.d &.e\");\n}\n",
|
||||
@ -92,10 +102,15 @@ test!(
|
||||
"a {\n color: e c.f, e d.f;\n}\n"
|
||||
);
|
||||
test!(
|
||||
nest_super_list_parent_inside_pseudo,
|
||||
nest_super_list_parent_inside_pseudo_matches,
|
||||
"a {\n color: selector-nest(\"c, d\", \":matches(&)\");\n}\n",
|
||||
"a {\n color: :matches(c, d);\n}\n"
|
||||
);
|
||||
test!(
|
||||
nest_super_list_parent_inside_pseudo_is,
|
||||
"a {\n color: selector-nest(\"c, d\", \":is(&)\");\n}\n",
|
||||
"a {\n color: :is(c, d);\n}\n"
|
||||
);
|
||||
test!(
|
||||
nest_super_list_multiple_parent,
|
||||
"a {\n color: selector-nest(\"c, d\", \"&.e &.f\");\n}\n",
|
||||
|
@ -46,6 +46,11 @@ test!(
|
||||
"a {\n color: selector-parse(\":matches(b, c)\");\n}\n",
|
||||
"a {\n color: :matches(b, c);\n}\n"
|
||||
);
|
||||
test!(
|
||||
pseudo_is_with_list_args,
|
||||
"a {\n color: selector-parse(\":is(b, c)\");\n}\n",
|
||||
"a {\n color: :is(b, c);\n}\n"
|
||||
);
|
||||
test!(
|
||||
pseudo_element,
|
||||
"a {\n color: selector-parse(\"::c\");\n}\n",
|
||||
|
@ -21,6 +21,11 @@ test!(
|
||||
"a {\n color: selector-replace(\":matches(c)\", \"c\", \"d\");\n}\n",
|
||||
"a {\n color: :matches(d);\n}\n"
|
||||
);
|
||||
test!(
|
||||
psuedo_is,
|
||||
"a {\n color: selector-replace(\":is(c)\", \"c\", \"d\");\n}\n",
|
||||
"a {\n color: :is(d);\n}\n"
|
||||
);
|
||||
test!(
|
||||
psuedo_not,
|
||||
"a {\n color: selector-replace(\":not(c)\", \"c\", \"d\");\n}\n",
|
||||
|
@ -668,3 +668,13 @@ test!(
|
||||
"a {\n color: selector-unify(\":matches(.c)\", \":matches(.d)\");\n}\n",
|
||||
"a {\n color: :matches(.c):matches(.d);\n}\n"
|
||||
);
|
||||
test!(
|
||||
simple_pseudo_arg_is_same_selector_arg,
|
||||
"a {\n color: selector-unify(\":is(.c)\", \":is(.c)\");\n}\n",
|
||||
"a {\n color: :is(.c);\n}\n"
|
||||
);
|
||||
test!(
|
||||
simple_pseudo_arg_is_different_selector_arg,
|
||||
"a {\n color: selector-unify(\":is(.c)\", \":is(.d)\");\n}\n",
|
||||
"a {\n color: :is(.c):is(.d);\n}\n"
|
||||
);
|
||||
|
@ -526,15 +526,21 @@ test!(
|
||||
"a:not(c) {\n x: y;\n}\n"
|
||||
);
|
||||
test!(
|
||||
psuedo_paren_removes_inner_placeholder,
|
||||
psuedo_paren_removes_inner_placeholder_matches,
|
||||
"a:matches(%b, c) {x: y}",
|
||||
"a:matches(c) {\n x: y;\n}\n"
|
||||
);
|
||||
test!(
|
||||
matches_placeholder_removes_everything,
|
||||
matches_placeholder_removes_everything_matches,
|
||||
"a:matches(%b) {x: y}",
|
||||
""
|
||||
);
|
||||
test!(
|
||||
psuedo_paren_removes_inner_placeholder_is,
|
||||
"a:is(%b, c) {x: y}",
|
||||
"a:is(c) {\n x: y;\n}\n"
|
||||
);
|
||||
test!(is_placeholder_removes_everything_is, "a:is(%b) {x: y}", "");
|
||||
test!(
|
||||
touching_universal_stays_the_same,
|
||||
"a* {\n color: red;\n}\n",
|
||||
|
Loading…
x
Reference in New Issue
Block a user