Skip to content

Commit 0536fd3

Browse files
feat(css): add support for sass() in SCSS conditional expressions (#9414)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 9c95b13 commit 0536fd3

File tree

45 files changed

+914
-339
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+914
-339
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/css/any/if_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ impl FormatRule<AnyCssIfTest> for FormatAnyCssIfTest {
1010
match node {
1111
AnyCssIfTest::CssBogusIfTest(node) => node.format().fmt(f),
1212
AnyCssIfTest::CssIfMediaTest(node) => node.format().fmt(f),
13+
AnyCssIfTest::CssIfSassTest(node) => node.format().fmt(f),
1314
AnyCssIfTest::CssIfStyleTest(node) => node.format().fmt(f),
1415
AnyCssIfTest::CssIfSupportsTest(node) => node.format().fmt(f),
1516
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use crate::prelude::*;
2+
use biome_css_syntax::{CssIfSassTest, CssIfSassTestFields};
3+
use biome_formatter::{format_args, write};
4+
#[derive(Debug, Clone, Default)]
5+
pub(crate) struct FormatCssIfSassTest;
6+
impl FormatNodeRule<CssIfSassTest> for FormatCssIfSassTest {
7+
fn fmt_fields(&self, node: &CssIfSassTest, f: &mut CssFormatter) -> FormatResult<()> {
8+
let CssIfSassTestFields {
9+
sass_token,
10+
l_paren_token,
11+
test,
12+
r_paren_token,
13+
} = node.as_fields();
14+
15+
write!(
16+
f,
17+
[
18+
sass_token.format(),
19+
group(&format_args![
20+
l_paren_token.format(),
21+
soft_block_indent(&test.format()),
22+
r_paren_token.format()
23+
])
24+
]
25+
)
26+
}
27+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub(crate) mod generic_delimiter;
5151
pub(crate) mod if_branch;
5252
pub(crate) mod if_function;
5353
pub(crate) mod if_media_test;
54+
pub(crate) mod if_sass_test;
5455
pub(crate) mod if_style_test;
5556
pub(crate) mod if_supports_identifier_test;
5657
pub(crate) mod if_supports_test;

crates/biome_css_formatter/src/generated.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,6 +2370,44 @@ impl IntoFormat<CssFormatContext> for biome_css_syntax::CssIfMediaTest {
23702370
)
23712371
}
23722372
}
2373+
impl FormatRule<biome_css_syntax::CssIfSassTest>
2374+
for crate::css::auxiliary::if_sass_test::FormatCssIfSassTest
2375+
{
2376+
type Context = CssFormatContext;
2377+
#[inline(always)]
2378+
fn fmt(
2379+
&self,
2380+
node: &biome_css_syntax::CssIfSassTest,
2381+
f: &mut CssFormatter,
2382+
) -> FormatResult<()> {
2383+
FormatNodeRule::<biome_css_syntax::CssIfSassTest>::fmt(self, node, f)
2384+
}
2385+
}
2386+
impl AsFormat<CssFormatContext> for biome_css_syntax::CssIfSassTest {
2387+
type Format<'a> = FormatRefWithRule<
2388+
'a,
2389+
biome_css_syntax::CssIfSassTest,
2390+
crate::css::auxiliary::if_sass_test::FormatCssIfSassTest,
2391+
>;
2392+
fn format(&self) -> Self::Format<'_> {
2393+
FormatRefWithRule::new(
2394+
self,
2395+
crate::css::auxiliary::if_sass_test::FormatCssIfSassTest::default(),
2396+
)
2397+
}
2398+
}
2399+
impl IntoFormat<CssFormatContext> for biome_css_syntax::CssIfSassTest {
2400+
type Format = FormatOwnedWithRule<
2401+
biome_css_syntax::CssIfSassTest,
2402+
crate::css::auxiliary::if_sass_test::FormatCssIfSassTest,
2403+
>;
2404+
fn into_format(self) -> Self::Format {
2405+
FormatOwnedWithRule::new(
2406+
self,
2407+
crate::css::auxiliary::if_sass_test::FormatCssIfSassTest::default(),
2408+
)
2409+
}
2410+
}
23732411
impl FormatRule<biome_css_syntax::CssIfStyleTest>
23742412
for crate::css::auxiliary::if_style_test::FormatCssIfStyleTest
23752413
{

crates/biome_css_formatter/tests/specs/css/scss/expression/edge-cases.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,11 @@ $paren-expr:(1+2*3 );
2424
2,
2525
3 4 );
2626
}
27+
28+
.c{
29+
inline-size:if(
30+
sass(
31+
$size > 10px
32+
):12px;
33+
else: 10px;);
34+
}

crates/biome_css_formatter/tests/specs/css/scss/expression/edge-cases.scss.snap

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
source: crates/biome_formatter_test/src/snapshot_builder.rs
3-
assertion_line: 212
43
info: css/scss/expression/edge-cases.scss
54
---
65

@@ -34,6 +33,14 @@ $paren-expr:(1+2*3 );
3433
3 4 );
3534
}
3635
36+
.c{
37+
inline-size:if(
38+
sass(
39+
$size > 10px
40+
):12px;
41+
else: 10px;);
42+
}
43+
3744
```
3845

3946

@@ -78,4 +85,8 @@ $kw-args: foo($a: 1, $b: 2, $c...);
7885
padding: (1 2, 3 4);
7986
}
8087
88+
.c {
89+
inline-size: if(sass($size > 10px): 12px; else: 10px);
90+
}
91+
8192
```

crates/biome_css_formatter/tests/specs/prettier/css/atrule/if-else.css.snap

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,6 @@ if-else.css:2:5 parse ━━━━━━━━━━━━━━━━━━━
538538
3 │ } @else if $media == phoneLandscape {
539539
4 │ $k: .08803;
540540
541-
i SCSS only syntax
542-
543541
if-else.css:4:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
544542
545543
× SCSS variable declarations are an SCSS only feature. Convert your file to an SCSS file or remove the syntax.
@@ -551,8 +549,6 @@ if-else.css:4:5 parse ━━━━━━━━━━━━━━━━━━━
551549
5 │ } @else if $media == tabletPortrait {
552550
6 │ $k: .065106;
553551
554-
i SCSS only syntax
555-
556552
if-else.css:6:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
557553
558554
× SCSS variable declarations are an SCSS only feature. Convert your file to an SCSS file or remove the syntax.
@@ -564,8 +560,6 @@ if-else.css:6:5 parse ━━━━━━━━━━━━━━━━━━━
564560
7 │ }
565561
8 │ p {
566562
567-
i SCSS only syntax
568-
569563
570564
```
571565

crates/biome_css_formatter/tests/specs/prettier/css/atrule/import.css.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,6 @@ import.css:42:1 parse ━━━━━━━━━━━━━━━━━━━
236236
43 │
237237
44 │ @import url("foo.css");
238238
239-
i SCSS only syntax
240-
241239
import.css:62:91 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
242240
243241
× expected `,` but instead found `tv`

0 commit comments

Comments
 (0)