Skip to content

Commit

Permalink
feat(css_parser): add :local and :global pseudo class. #3011
Browse files Browse the repository at this point in the history
  • Loading branch information
denbezrukov committed May 28, 2024
1 parent 19ac556 commit 9a752ed
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::prelude::*;
use biome_css_syntax::CssValueAtRuleImportClause;
use biome_rowan::AstNode;
use biome_css_syntax::{CssValueAtRuleImportClause, CssValueAtRuleImportClauseFields};
use biome_formatter::write;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssValueAtRuleImportClause;
impl FormatNodeRule<CssValueAtRuleImportClause> for FormatCssValueAtRuleImportClause {
Expand All @@ -9,6 +10,21 @@ impl FormatNodeRule<CssValueAtRuleImportClause> for FormatCssValueAtRuleImportCl
node: &CssValueAtRuleImportClause,
f: &mut CssFormatter,
) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let CssValueAtRuleImportClauseFields {
specifiers,
from_token,
source,
} = node.as_fields();

write!(
f,
[
specifiers.format(),
space(),
from_token.format(),
space(),
source.format()
]
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::prelude::*;
use biome_css_syntax::CssValueAtRuleImportSpecifier;
use biome_rowan::AstNode;
use biome_css_syntax::{CssValueAtRuleImportSpecifier, CssValueAtRuleImportSpecifierFields};
use biome_formatter::write;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssValueAtRuleImportSpecifier;
impl FormatNodeRule<CssValueAtRuleImportSpecifier> for FormatCssValueAtRuleImportSpecifier {
Expand All @@ -9,6 +10,8 @@ impl FormatNodeRule<CssValueAtRuleImportSpecifier> for FormatCssValueAtRuleImpor
node: &CssValueAtRuleImportSpecifier,
f: &mut CssFormatter,
) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let CssValueAtRuleImportSpecifierFields { name } = node.as_fields();

write!(f, [name.format()])
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::prelude::*;
use biome_css_syntax::CssValueAtRuleNamedImportSpecifier;
use biome_rowan::AstNode;
use biome_css_syntax::{
CssValueAtRuleNamedImportSpecifier, CssValueAtRuleNamedImportSpecifierFields,
};
use biome_formatter::write;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssValueAtRuleNamedImportSpecifier;
impl FormatNodeRule<CssValueAtRuleNamedImportSpecifier>
Expand All @@ -11,6 +14,21 @@ impl FormatNodeRule<CssValueAtRuleNamedImportSpecifier>
node: &CssValueAtRuleNamedImportSpecifier,
f: &mut CssFormatter,
) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let CssValueAtRuleNamedImportSpecifierFields {
name,
as_token,
local_name,
} = node.as_fields();

write!(
f,
[
name.format(),
space(),
as_token.format(),
space(),
local_name.format()
]
)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::prelude::*;
use biome_css_syntax::CssValueAtRuleImportSpecifierList;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssValueAtRuleImportSpecifierList;
impl FormatRule<CssValueAtRuleImportSpecifierList> for FormatCssValueAtRuleImportSpecifierList {
Expand All @@ -9,6 +10,13 @@ impl FormatRule<CssValueAtRuleImportSpecifierList> for FormatCssValueAtRuleImpor
node: &CssValueAtRuleImportSpecifierList,
f: &mut CssFormatter,
) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
let separator = space();
let mut joiner = f.join_with(&separator);

for formatted in node.format_separated(",") {
joiner.entry(&formatted);
}

joiner.finish()
}
}
40 changes: 40 additions & 0 deletions crates/biome_css_formatter/tests/specs/css/atrule/value.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@value
colors:
"./colors.css";
@value
primary,
secondary from
colors
;
@value
small
as
bp-small,
medium,
large as
bp-large from
"./breakpoints.css";
@value
selectorValue:
secondary-color;
@value
small:
(max-width:
599px);
@value
medium:
(min-width: 600px) and (max-width: 959px);
@value
large:
(min-width: 960px);
@value
primary:
#BF4040;
@value
secondary:
#1F4F7F;
@value
common-gradient:
transparent 75%,
var(--ring-line-color) 75%,
currentColor 79%;
102 changes: 102 additions & 0 deletions crates/biome_css_formatter/tests/specs/css/atrule/value.css.snap.new
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
source: crates/biome_formatter_test/src/snapshot_builder.rs
assertion_line: 212
info: css/atrule/value.css
---
# Input

```css
@value
colors:
"./colors.css";
@value
primary,
secondary from
colors
;
@value
small
as
bp-small,
medium,
large as
bp-large from
"./breakpoints.css";
@value
selectorValue:
secondary-color;
@value
small:
(max-width:
599px);
@value
medium:
(min-width: 600px) and (max-width: 959px);
@value
large:
(min-width: 960px);
@value
primary:
#BF4040;
@value
secondary:
#1F4F7F;
@value
common-gradient:
transparent 75%,
var(--ring-line-color) 75%,
currentColor 79%;

```


=============================

# Outputs

## Output 1

-----
Indent style: Tab
Indent width: 2
Line ending: LF
Line width: 80
Quote style: Double Quotes
-----

```css
@value colors:
"./colors.css";
@value primary, secondary from colors;
@value small as bp-small, medium, large as bp-large from "./breakpoints.css";
@value selectorValue:
secondary-color;
@value small:
(max-width:
599px);
@value medium:
(min-width: 600px) and (max-width: 959px);
@value large:
(min-width: 960px);
@value primary:
#BF4040;
@value secondary:
#1F4F7F;
@value common-gradient:
transparent 75%,
var(--ring-line-color) 75%,
currentColor 79%;
```



## Unimplemented nodes/tokens

" colors:\n\"./colors.css\"" => 6..29
" selectorValue:\nsecondary-color" => 154..185
" small:\n(max-width:\n599px)" => 193..219
" medium:\n(min-width: 600px) and (max-width: 959px)" => 227..277
" large:\n(min-width: 960px)" => 285..311
" primary:\n#BF4040" => 319..336
" secondary:\n#1F4F7F" => 344..363
" common-gradient:\ntransparent 75%,\nvar(--ring-line-color) 75%,\ncurrentColor 79%" => 371..450

0 comments on commit 9a752ed

Please sign in to comment.