Skip to content

Commit 071d9b9

Browse files
authored
feat(css): parse scss interpolation expressions (#9472)
1 parent 058f7b5 commit 071d9b9

File tree

24 files changed

+1048
-4
lines changed

24 files changed

+1048
-4
lines changed

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/generated.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7979,6 +7979,44 @@ impl IntoFormat<CssFormatContext> for biome_css_syntax::ScssIncludeAtRule {
79797979
)
79807980
}
79817981
}
7982+
impl FormatRule<biome_css_syntax::ScssInterpolation>
7983+
for crate::scss::auxiliary::interpolation::FormatScssInterpolation
7984+
{
7985+
type Context = CssFormatContext;
7986+
#[inline(always)]
7987+
fn fmt(
7988+
&self,
7989+
node: &biome_css_syntax::ScssInterpolation,
7990+
f: &mut CssFormatter,
7991+
) -> FormatResult<()> {
7992+
FormatNodeRule::<biome_css_syntax::ScssInterpolation>::fmt(self, node, f)
7993+
}
7994+
}
7995+
impl AsFormat<CssFormatContext> for biome_css_syntax::ScssInterpolation {
7996+
type Format<'a> = FormatRefWithRule<
7997+
'a,
7998+
biome_css_syntax::ScssInterpolation,
7999+
crate::scss::auxiliary::interpolation::FormatScssInterpolation,
8000+
>;
8001+
fn format(&self) -> Self::Format<'_> {
8002+
FormatRefWithRule::new(
8003+
self,
8004+
crate::scss::auxiliary::interpolation::FormatScssInterpolation::default(),
8005+
)
8006+
}
8007+
}
8008+
impl IntoFormat<CssFormatContext> for biome_css_syntax::ScssInterpolation {
8009+
type Format = FormatOwnedWithRule<
8010+
biome_css_syntax::ScssInterpolation,
8011+
crate::scss::auxiliary::interpolation::FormatScssInterpolation,
8012+
>;
8013+
fn into_format(self) -> Self::Format {
8014+
FormatOwnedWithRule::new(
8015+
self,
8016+
crate::scss::auxiliary::interpolation::FormatScssInterpolation::default(),
8017+
)
8018+
}
8019+
}
79828020
impl FormatRule<biome_css_syntax::ScssKeywordArgument>
79838021
for crate::scss::auxiliary::keyword_argument::FormatScssKeywordArgument
79848022
{

crates/biome_css_formatter/src/scss/any/expression.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ impl FormatRule<AnyScssExpression> for FormatAnyScssExpression {
1111
AnyScssExpression::AnyCssValue(node) => node.format().fmt(f),
1212
AnyScssExpression::ScssBinaryExpression(node) => node.format().fmt(f),
1313
AnyScssExpression::ScssExpression(node) => node.format().fmt(f),
14+
AnyScssExpression::ScssInterpolation(node) => node.format().fmt(f),
1415
AnyScssExpression::ScssListExpression(node) => node.format().fmt(f),
1516
AnyScssExpression::ScssMapExpression(node) => node.format().fmt(f),
1617
AnyScssExpression::ScssParenthesizedExpression(node) => node.format().fmt(f),

crates/biome_css_formatter/src/scss/any/expression_item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ impl FormatRule<AnyScssExpressionItem> for FormatAnyScssExpressionItem {
1313
AnyScssExpressionItem::CssGenericDelimiter(node) => node.format().fmt(f),
1414
AnyScssExpressionItem::ScssArbitraryArgument(node) => node.format().fmt(f),
1515
AnyScssExpressionItem::ScssBinaryExpression(node) => node.format().fmt(f),
16+
AnyScssExpressionItem::ScssInterpolation(node) => node.format().fmt(f),
1617
AnyScssExpressionItem::ScssKeywordArgument(node) => node.format().fmt(f),
1718
AnyScssExpressionItem::ScssListExpression(node) => node.format().fmt(f),
1819
AnyScssExpressionItem::ScssMapExpression(node) => node.format().fmt(f),
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use crate::prelude::*;
2+
use biome_css_syntax::{ScssInterpolation, ScssInterpolationFields};
3+
use biome_formatter::{format_args, write};
4+
5+
#[derive(Debug, Clone, Default)]
6+
pub(crate) struct FormatScssInterpolation;
7+
impl FormatNodeRule<ScssInterpolation> for FormatScssInterpolation {
8+
fn fmt_fields(&self, node: &ScssInterpolation, f: &mut CssFormatter) -> FormatResult<()> {
9+
let ScssInterpolationFields {
10+
hash_token,
11+
l_curly_token,
12+
value,
13+
r_curly_token,
14+
} = node.as_fields();
15+
16+
write!(
17+
f,
18+
[group(&format_args![
19+
hash_token.format(),
20+
l_curly_token.format(),
21+
value.format(),
22+
r_curly_token.format()
23+
])]
24+
)
25+
}
26+
}

crates/biome_css_formatter/src/scss/auxiliary/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub(crate) mod extend_optional_modifier;
1010
pub(crate) mod forward_as_clause;
1111
pub(crate) mod hide_clause;
1212
pub(crate) mod include_argument_list;
13+
pub(crate) mod interpolation;
1314
pub(crate) mod keyword_argument;
1415
pub(crate) mod list_expression;
1516
pub(crate) mod list_expression_element;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
$direct:#{$name};
2+
$binary:#{1+2};
3+
$nested:#{($a+1)*2};
4+
$call:#{map-get($map,
5+
key)};
6+
$list:#{1,2,3};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
source: crates/biome_formatter_test/src/snapshot_builder.rs
3+
assertion_line: 212
4+
info: css/scss/expression/interpolation.scss
5+
---
6+
7+
# Input
8+
9+
```scss
10+
$direct:#{$name};
11+
$binary:#{1+2};
12+
$nested:#{($a+1)*2};
13+
$call:#{map-get($map,
14+
key)};
15+
$list:#{1,2,3};
16+
17+
```
18+
19+
20+
=============================
21+
22+
# Outputs
23+
24+
## Output 1
25+
26+
-----
27+
Indent style: Tab
28+
Indent width: 2
29+
Line ending: LF
30+
Line width: 80
31+
Quote style: Double Quotes
32+
Trailing newline: true
33+
-----
34+
35+
```scss
36+
$direct: #{$name};
37+
$binary: #{1 + 2};
38+
$nested: #{($a + 1) * 2};
39+
$call: #{map-get($map, key)};
40+
$list: #{1, 2, 3};
41+
42+
```

crates/biome_css_parser/src/lexer/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#![expect(unused_mut, unused_variables)]
33

44
use super::{CssLexer, TextSize};
5+
use biome_css_syntax::CssSyntaxKind::EOF;
56
use crate::lexer::CssLexContext;
67
use crate::CssParserOptions;
7-
use biome_css_syntax::CssSyntaxKind::EOF;
88
use biome_parser::lexer::Lexer;
99
use quickcheck_macros::quickcheck;
1010
use std::sync::mpsc::channel;

0 commit comments

Comments
 (0)