Skip to content

Commit a2faf99

Browse files
authored
Add support for ::grammar-error and ::spelling-error (#1026)
Closes: #1021
1 parent 2fae1a2 commit a2faf99

4 files changed

Lines changed: 60 additions & 0 deletions

File tree

scripts/build-prefixes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ let mdnFeatures = {
341341
picker: mdn.css.selectors.picker.__compat.support,
342342
pickerIcon: mdn.css.selectors['picker-icon'].__compat.support,
343343
checkmark: mdn.css.selectors.checkmark.__compat.support,
344+
grammarError: mdn.css.selectors['grammar-error'].__compat.support,
345+
spellingError: mdn.css.selectors['spelling-error'].__compat.support,
344346
};
345347

346348
for (let key in mdn.css.types.length) {

selectors/parser.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3938,6 +3938,11 @@ pub mod tests {
39383938
assert!(parse("::picker(select)").is_ok());
39393939
assert!(parse("select::picker-icon").is_ok());
39403940
assert!(parse("option::checkmark").is_ok());
3941+
3942+
assert!(parse("::grammar-error").is_ok());
3943+
assert!(parse("::spelling-error").is_ok());
3944+
assert!(parse("::part(mypart)::grammar-error").is_ok());
3945+
assert!(parse("::part(mypart)::spelling-error").is_ok());
39413946
}
39423947

39433948
#[test]

src/compat.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub enum Feature {
8787
Gencontent,
8888
GeorgianListStyleType,
8989
GradientInterpolationHints,
90+
GrammarError,
9091
GujaratiListStyleType,
9192
GurmukhiListStyleType,
9293
HasSelector,
@@ -189,6 +190,7 @@ pub enum Feature {
189190
SimpChineseFormalListStyleType,
190191
SimpChineseInformalListStyleType,
191192
SomaliListStyleType,
193+
SpellingError,
192194
SpaceSeparatedColorNotation,
193195
SquareListStyleType,
194196
StretchSize,
@@ -5595,6 +5597,46 @@ impl Feature {
55955597
return false;
55965598
}
55975599
}
5600+
Feature::GrammarError | Feature::SpellingError => {
5601+
if let Some(version) = browsers.chrome {
5602+
if version < 7929856 { // Chrome 121
5603+
return false;
5604+
}
5605+
}
5606+
if let Some(version) = browsers.edge {
5607+
if version < 7929856 { // Edge 121
5608+
return false;
5609+
}
5610+
}
5611+
if let Some(version) = browsers.opera {
5612+
if version < 7929856 { // Opera 121
5613+
return false;
5614+
}
5615+
}
5616+
if let Some(version) = browsers.safari {
5617+
if version < 1115136 { // Safari 17.4
5618+
return false;
5619+
}
5620+
}
5621+
if let Some(version) = browsers.ios_saf {
5622+
if version < 1115136 { // iOS Safari 17.4
5623+
return false;
5624+
}
5625+
}
5626+
if let Some(version) = browsers.android {
5627+
if version < 7929856 { // Android Chrome 121
5628+
return false;
5629+
}
5630+
}
5631+
if let Some(version) = browsers.samsung {
5632+
if version < 7929856 { // Samsung Internet 121
5633+
return false;
5634+
}
5635+
}
5636+
if browsers.firefox.is_some() || browsers.ie.is_some() {
5637+
return false;
5638+
}
5639+
}
55985640
Feature::P3Colors | Feature::LangSelectorList => {
55995641
if let Some(version) = browsers.safari {
56005642
if version < 655616 {

src/selector.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ impl<'a, 'o, 'i> parcel_selectors::parser::Parser<'i> for SelectorParser<'a, 'o,
297297

298298
"view-transition" => ViewTransition,
299299

300+
"grammar-error" => GrammarError,
301+
"spelling-error" => SpellingError,
302+
300303
_ => {
301304
if !name.starts_with('-') {
302305
self.options.warn(loc.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoElement(name.clone())));
@@ -966,6 +969,10 @@ pub enum PseudoElement<'i> {
966969
PickerIcon,
967970
/// The [::checkmark](https://drafts.csswg.org/css-forms-1/#styling-checkmarks-the-checkmark-pseudo-element) pseudo element.
968971
Checkmark,
972+
/// The [::grammar-error](https://drafts.csswg.org/css-pseudo/#selectordef-grammar-error) pseudo element.
973+
GrammarError,
974+
/// The [::spelling-error](https://drafts.csswg.org/css-pseudo/#selectordef-spelling-error) pseudo element.
975+
SpellingError,
969976
/// An unknown pseudo element.
970977
Custom {
971978
/// The name of the pseudo element.
@@ -1233,6 +1240,8 @@ where
12331240
}
12341241
PickerIcon => dest.write_str("::picker-icon"),
12351242
Checkmark => dest.write_str("::checkmark"),
1243+
GrammarError => dest.write_str("::grammar-error"),
1244+
SpellingError => dest.write_str("::spelling-error"),
12361245
Custom { name: val } => {
12371246
dest.write_str("::")?;
12381247
return dest.write_str(val);
@@ -1947,6 +1956,8 @@ pub(crate) fn is_compatible(selectors: &[Selector], targets: Targets) -> bool {
19471956
PseudoElement::PickerFunction { identifier: _ } => Feature::Picker,
19481957
PseudoElement::PickerIcon => Feature::PickerIcon,
19491958
PseudoElement::Checkmark => Feature::Checkmark,
1959+
PseudoElement::GrammarError => Feature::GrammarError,
1960+
PseudoElement::SpellingError => Feature::SpellingError,
19501961
PseudoElement::Custom { name: _ } | _ => return false,
19511962
},
19521963

0 commit comments

Comments
 (0)