Skip to content

Commit 29e4229

Browse files
ryan-m-walkerematipicocoderabbitai[bot]
authored
fix(css_parser): add support for parsing :state() (#7619) (#7665)
Co-authored-by: Emanuele Stoppa <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 8cefae2 commit 29e4229

File tree

37 files changed

+1827
-1
lines changed

37 files changed

+1827
-1
lines changed

.changeset/salty-cats-jog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#7619](https://github.com/biomejs/biome/issues/7619): Added support for parsing the CSS `:state()` pseudo-class.
6+
7+
```css
8+
custom-selector:state(checked) {
9+
10+
}
11+
```

crates/biome_css_analyze/tests/specs/correctness/noUnknownPseudoClass/valid.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ a:defined { }
3838
:seeking, :stalled, :buffering, :volume-locked, :muted {}
3939
::-webkit-scrollbar-button:hover {}
4040
dialog:open {}
41+
custom-selector:state(checked) {}

crates/biome_css_analyze/tests/specs/correctness/noUnknownPseudoClass/valid.css.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ a:defined { }
4444
:seeking, :stalled, :buffering, :volume-locked, :muted {}
4545
::-webkit-scrollbar-button:hover {}
4646
dialog:open {}
47+
custom-selector:state(checked) {}
4748
4849
```

crates/biome_css_factory/src/generated/node_factory.rs

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_css_factory/src/generated/syntax_factory.rs

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_css_formatter/src/css/any/pseudo_class.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ impl FormatRule<AnyCssPseudoClass> for FormatAnyCssPseudoClass {
1313
AnyCssPseudoClass::CssPseudoClassFunctionCompoundSelectorList(node) => {
1414
node.format().fmt(f)
1515
}
16+
AnyCssPseudoClass::CssPseudoClassFunctionCustomIdentifier(node) => node.format().fmt(f),
1617
AnyCssPseudoClass::CssPseudoClassFunctionCustomIdentifierList(node) => {
1718
node.format().fmt(f)
1819
}

crates/biome_css_formatter/src/css/pseudo/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
pub(crate) mod page_selector_pseudo;
44
pub(crate) mod pseudo_class_function_compound_selector_list;
5+
pub(crate) mod pseudo_class_function_custom_identifier;
56
pub(crate) mod pseudo_class_function_custom_identifier_list;
67
pub(crate) mod pseudo_class_function_identifier;
78
pub(crate) mod pseudo_class_function_nth;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use crate::css::value::identifier::FormatCssIdentifierOptions;
2+
use crate::prelude::*;
3+
use biome_css_syntax::{
4+
CssPseudoClassFunctionCustomIdentifier, CssPseudoClassFunctionCustomIdentifierFields,
5+
};
6+
use biome_formatter::{format_args, write};
7+
8+
#[derive(Debug, Clone, Default)]
9+
pub(crate) struct FormatCssPseudoClassFunctionCustomIdentifier;
10+
impl FormatNodeRule<CssPseudoClassFunctionCustomIdentifier>
11+
for FormatCssPseudoClassFunctionCustomIdentifier
12+
{
13+
fn fmt_fields(
14+
&self,
15+
node: &CssPseudoClassFunctionCustomIdentifier,
16+
f: &mut CssFormatter,
17+
) -> FormatResult<()> {
18+
let CssPseudoClassFunctionCustomIdentifierFields {
19+
name,
20+
l_paren_token,
21+
ident,
22+
r_paren_token,
23+
} = node.as_fields();
24+
25+
write!(
26+
f,
27+
[
28+
name.format()?
29+
.with_options(FormatCssIdentifierOptions::default().with_lowercasing()),
30+
group(&format_args![
31+
l_paren_token.format(),
32+
soft_block_indent(&ident.format()),
33+
r_paren_token.format()
34+
])
35+
]
36+
)
37+
}
38+
}

crates/biome_css_formatter/src/generated.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3386,6 +3386,19 @@ impl IntoFormat<CssFormatContext> for biome_css_syntax::CssPseudoClassFunctionCo
33863386
FormatOwnedWithRule :: new (self , crate :: css :: pseudo :: pseudo_class_function_compound_selector_list :: FormatCssPseudoClassFunctionCompoundSelectorList :: default ())
33873387
}
33883388
}
3389+
impl FormatRule < biome_css_syntax :: CssPseudoClassFunctionCustomIdentifier > for crate :: css :: pseudo :: pseudo_class_function_custom_identifier :: FormatCssPseudoClassFunctionCustomIdentifier { type Context = CssFormatContext ; # [inline (always)] fn fmt (& self , node : & biome_css_syntax :: CssPseudoClassFunctionCustomIdentifier , f : & mut CssFormatter) -> FormatResult < () > { FormatNodeRule :: < biome_css_syntax :: CssPseudoClassFunctionCustomIdentifier > :: fmt (self , node , f) } }
3390+
impl AsFormat<CssFormatContext> for biome_css_syntax::CssPseudoClassFunctionCustomIdentifier {
3391+
type Format < 'a > = FormatRefWithRule < 'a , biome_css_syntax :: CssPseudoClassFunctionCustomIdentifier , crate :: css :: pseudo :: pseudo_class_function_custom_identifier :: FormatCssPseudoClassFunctionCustomIdentifier > ;
3392+
fn format(&self) -> Self::Format<'_> {
3393+
FormatRefWithRule :: new (self , crate :: css :: pseudo :: pseudo_class_function_custom_identifier :: FormatCssPseudoClassFunctionCustomIdentifier :: default ())
3394+
}
3395+
}
3396+
impl IntoFormat<CssFormatContext> for biome_css_syntax::CssPseudoClassFunctionCustomIdentifier {
3397+
type Format = FormatOwnedWithRule < biome_css_syntax :: CssPseudoClassFunctionCustomIdentifier , crate :: css :: pseudo :: pseudo_class_function_custom_identifier :: FormatCssPseudoClassFunctionCustomIdentifier > ;
3398+
fn into_format(self) -> Self::Format {
3399+
FormatOwnedWithRule :: new (self , crate :: css :: pseudo :: pseudo_class_function_custom_identifier :: FormatCssPseudoClassFunctionCustomIdentifier :: default ())
3400+
}
3401+
}
33893402
impl FormatRule < biome_css_syntax :: CssPseudoClassFunctionCustomIdentifierList > for crate :: css :: pseudo :: pseudo_class_function_custom_identifier_list :: FormatCssPseudoClassFunctionCustomIdentifierList { type Context = CssFormatContext ; # [inline (always)] fn fmt (& self , node : & biome_css_syntax :: CssPseudoClassFunctionCustomIdentifierList , f : & mut CssFormatter) -> FormatResult < () > { FormatNodeRule :: < biome_css_syntax :: CssPseudoClassFunctionCustomIdentifierList > :: fmt (self , node , f) } }
33903403
impl AsFormat<CssFormatContext> for biome_css_syntax::CssPseudoClassFunctionCustomIdentifierList {
33913404
type Format < 'a > = FormatRefWithRule < 'a , biome_css_syntax :: CssPseudoClassFunctionCustomIdentifierList , crate :: css :: pseudo :: pseudo_class_function_custom_identifier_list :: FormatCssPseudoClassFunctionCustomIdentifierList > ;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
custom-selector:state(checked) {}
2+
custom-selector:state( checked) {}
3+
custom-selector:state( checked ) {}
4+
custom-selector:state(
5+
checked
6+
) {}
7+
8+
:host(
9+
:state( checked
10+
))::before { }
11+
:host(:state( checked
12+
)
13+
)::before { }

0 commit comments

Comments
 (0)