Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions crates/biome_css_factory/src/generated/node_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions crates/biome_css_factory/src/generated/syntax_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions crates/biome_css_formatter/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7979,6 +7979,44 @@ impl IntoFormat<CssFormatContext> for biome_css_syntax::ScssIncludeAtRule {
)
}
}
impl FormatRule<biome_css_syntax::ScssInterpolation>
for crate::scss::auxiliary::interpolation::FormatScssInterpolation
{
type Context = CssFormatContext;
#[inline(always)]
fn fmt(
&self,
node: &biome_css_syntax::ScssInterpolation,
f: &mut CssFormatter,
) -> FormatResult<()> {
FormatNodeRule::<biome_css_syntax::ScssInterpolation>::fmt(self, node, f)
}
}
impl AsFormat<CssFormatContext> for biome_css_syntax::ScssInterpolation {
type Format<'a> = FormatRefWithRule<
'a,
biome_css_syntax::ScssInterpolation,
crate::scss::auxiliary::interpolation::FormatScssInterpolation,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::scss::auxiliary::interpolation::FormatScssInterpolation::default(),
)
}
}
impl IntoFormat<CssFormatContext> for biome_css_syntax::ScssInterpolation {
type Format = FormatOwnedWithRule<
biome_css_syntax::ScssInterpolation,
crate::scss::auxiliary::interpolation::FormatScssInterpolation,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::scss::auxiliary::interpolation::FormatScssInterpolation::default(),
)
}
}
impl FormatRule<biome_css_syntax::ScssKeywordArgument>
for crate::scss::auxiliary::keyword_argument::FormatScssKeywordArgument
{
Expand Down
1 change: 1 addition & 0 deletions crates/biome_css_formatter/src/scss/any/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ impl FormatRule<AnyScssExpression> for FormatAnyScssExpression {
AnyScssExpression::AnyCssValue(node) => node.format().fmt(f),
AnyScssExpression::ScssBinaryExpression(node) => node.format().fmt(f),
AnyScssExpression::ScssExpression(node) => node.format().fmt(f),
AnyScssExpression::ScssInterpolation(node) => node.format().fmt(f),
AnyScssExpression::ScssListExpression(node) => node.format().fmt(f),
AnyScssExpression::ScssMapExpression(node) => node.format().fmt(f),
AnyScssExpression::ScssParenthesizedExpression(node) => node.format().fmt(f),
Expand Down
1 change: 1 addition & 0 deletions crates/biome_css_formatter/src/scss/any/expression_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ impl FormatRule<AnyScssExpressionItem> for FormatAnyScssExpressionItem {
AnyScssExpressionItem::CssGenericDelimiter(node) => node.format().fmt(f),
AnyScssExpressionItem::ScssArbitraryArgument(node) => node.format().fmt(f),
AnyScssExpressionItem::ScssBinaryExpression(node) => node.format().fmt(f),
AnyScssExpressionItem::ScssInterpolation(node) => node.format().fmt(f),
AnyScssExpressionItem::ScssKeywordArgument(node) => node.format().fmt(f),
AnyScssExpressionItem::ScssListExpression(node) => node.format().fmt(f),
AnyScssExpressionItem::ScssMapExpression(node) => node.format().fmt(f),
Expand Down
26 changes: 26 additions & 0 deletions crates/biome_css_formatter/src/scss/auxiliary/interpolation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use crate::prelude::*;
use biome_css_syntax::{ScssInterpolation, ScssInterpolationFields};
use biome_formatter::{format_args, write};

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatScssInterpolation;
impl FormatNodeRule<ScssInterpolation> for FormatScssInterpolation {
fn fmt_fields(&self, node: &ScssInterpolation, f: &mut CssFormatter) -> FormatResult<()> {
let ScssInterpolationFields {
hash_token,
l_curly_token,
value,
r_curly_token,
} = node.as_fields();

write!(
f,
[group(&format_args![
hash_token.format(),
l_curly_token.format(),
value.format(),
r_curly_token.format()
])]
)
}
}
1 change: 1 addition & 0 deletions crates/biome_css_formatter/src/scss/auxiliary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub(crate) mod extend_optional_modifier;
pub(crate) mod forward_as_clause;
pub(crate) mod hide_clause;
pub(crate) mod include_argument_list;
pub(crate) mod interpolation;
pub(crate) mod keyword_argument;
pub(crate) mod list_expression;
pub(crate) mod list_expression_element;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$direct:#{$name};
$binary:#{1+2};
$nested:#{($a+1)*2};
$call:#{map-get($map,
key)};
$list:#{1,2,3};
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
source: crates/biome_formatter_test/src/snapshot_builder.rs
assertion_line: 212
info: css/scss/expression/interpolation.scss
---

# Input

```scss
$direct:#{$name};
$binary:#{1+2};
$nested:#{($a+1)*2};
$call:#{map-get($map,
key)};
$list:#{1,2,3};

```


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

# Outputs

## Output 1

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

```scss
$direct: #{$name};
$binary: #{1 + 2};
$nested: #{($a + 1) * 2};
$call: #{map-get($map, key)};
$list: #{1, 2, 3};

```
2 changes: 1 addition & 1 deletion crates/biome_css_parser/src/lexer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#![expect(unused_mut, unused_variables)]

use super::{CssLexer, TextSize};
use biome_css_syntax::CssSyntaxKind::EOF;
use crate::lexer::CssLexContext;
use crate::CssParserOptions;
use biome_css_syntax::CssSyntaxKind::EOF;
use biome_parser::lexer::Lexer;
use quickcheck_macros::quickcheck;
use std::sync::mpsc::channel;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use crate::parser::CssParser;
use biome_css_syntax::CssSyntaxKind::SCSS_INTERPOLATION;
use biome_css_syntax::{CssSyntaxKind, T};
use biome_parser::prelude::ParsedSyntax::{Absent, Present};
use biome_parser::prelude::*;
use biome_parser::{TokenSet, token_set};

use super::list::parse_scss_inner_expression_until;
use crate::syntax::scss::expected_scss_expression;

const SCSS_INTERPOLATION_END_TOKEN_SET: TokenSet<CssSyntaxKind> = token_set![T!['}'], T![;]];

/// Parses a standalone SCSS interpolation expression such as `#{$value}`.
///
/// Example:
/// ```scss
/// $value: #{$name};
/// ```
///
/// Docs: https://sass-lang.com/documentation/interpolation/
#[inline]
pub(super) fn parse_scss_interpolation(p: &mut CssParser) -> ParsedSyntax {
if !is_at_scss_interpolation(p) {
return Absent;
}

let m = p.start();

p.bump(T![#]);
p.bump(T!['{']);
parse_scss_inner_expression_until(p, SCSS_INTERPOLATION_END_TOKEN_SET)
.or_add_diagnostic(p, expected_scss_expression);
p.expect(T!['}']);

Present(m.complete(p, SCSS_INTERPOLATION))
}

#[inline]
pub(super) fn is_at_scss_interpolation(p: &mut CssParser) -> bool {
p.at(T![#]) && p.nth_at(1, T!['{'])
}
1 change: 1 addition & 0 deletions crates/biome_css_parser/src/syntax/scss/expression/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod interpolation;
mod list;
mod map;
mod precedence;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use biome_css_syntax::T;
use biome_parser::Parser;
use biome_parser::prelude::ParsedSyntax;

use super::interpolation::{is_at_scss_interpolation, parse_scss_interpolation};
use super::map::parse_scss_parenthesized_or_map_expression;

/// Parses SCSS primaries such as parenthesized values, maps, `!important`, and
Expand All @@ -19,7 +20,9 @@ use super::map::parse_scss_parenthesized_or_map_expression;
/// Docs: https://sass-lang.com/documentation/at-rules/function
#[inline]
pub(super) fn parse_scss_primary_expression(p: &mut CssParser) -> ParsedSyntax {
if p.at(T!['(']) {
if is_at_scss_interpolation(p) {
parse_scss_interpolation(p)
} else if p.at(T!['(']) {
parse_scss_parenthesized_or_map_expression(p)
} else if is_at_declaration_important(p) {
parse_declaration_important(p)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$unclosed: #{$name;
$empty: #{};
$missing-rhs: #{1 + };
Loading
Loading