Skip to content

feat(css): add SCSS unary and binary expression#9222

Merged
denbezrukov merged 4 commits intomainfrom
db/scss-binary
Feb 24, 2026
Merged

feat(css): add SCSS unary and binary expression#9222
denbezrukov merged 4 commits intomainfrom
db/scss-binary

Conversation

@denbezrukov
Copy link
Contributor

Summary

New Scss syntax:

 $expr1: $a + $b * $c;
  $expr2: ($a + $b) * $c;
  $expr3: $a * $b + $c;
  $expr4: -$a + $b;
  $expr5: not $a and $b;
  $expr6: $a == $b or $c != $d;

Test Plan

cargo test -p biome_css_parser
cargo test -p biome_css_formatter

@changeset-bot
Copy link

changeset-bot bot commented Feb 24, 2026

⚠️ No Changeset found

Latest commit: 796df4d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added A-Parser Area: parser A-Formatter Area: formatter A-Tooling Area: internal tools L-CSS Language: CSS L-Grit Language: GritQL labels Feb 24, 2026
@github-actions
Copy link
Contributor

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 52917 52917 0
Passed 51697 51697 0
Failed 1178 1178 0
Panics 42 42 0
Coverage 97.69% 97.69% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 38 38 0
Passed 37 37 0
Failed 1 1 0
Panics 0 0 0
Coverage 97.37% 97.37% 0.00%

markdown/commonmark

Test result main count This PR count Difference
Total 652 652 0
Passed 652 652 0
Failed 0 0 0
Panics 0 0 0
Coverage 100.00% 100.00% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5464 5464 0
Passed 1915 1915 0
Failed 3549 3549 0
Panics 0 0 0
Coverage 35.05% 35.05% 0.00%

ts/babel

Test result main count This PR count Difference
Total 635 635 0
Passed 567 567 0
Failed 68 68 0
Panics 0 0 0
Coverage 89.29% 89.29% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 18871 18871 0
Passed 13012 13012 0
Failed 5858 5858 0
Panics 1 1 0
Coverage 68.95% 68.95% 0.00%

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 24, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks
⏩ 187 skipped benchmarks1


Comparing db/scss-binary (796df4d) with main (de4c5f6)

Open in CodSpeed

Footnotes

  1. 187 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 24, 2026

Walkthrough

Adds SCSS binary and unary expression support across parser, lexer, formatter and tests. New AST nodes ScssBinaryExpression and ScssUnaryExpression and token == are introduced; parser gains Pratt-style precedence parsing and exposes parse_scss_expression_until; lexer recognises ==/!= in SCSS; formatter implements FormatRule/AsFormat/IntoFormat and node-formatters for the new SCSS nodes; tests exercise precedence and formatter output.

Possibly related PRs

Suggested reviewers

  • ematipico
  • siketyan
  • dyc3
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: introducing SCSS unary and binary expression support to the CSS formatter and parser.
Description check ✅ Passed The description provides relevant context with concrete SCSS expression examples demonstrating the new syntax and includes a clear test plan for validation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch db/scss-binary

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
crates/biome_css_parser/src/syntax/scss/expression/mod.rs (2)

56-62: parse_scss_inner_expression_until is identical to parse_scss_expression_until.

Both call parse_scss_expression_with_options(p, end_ts, false). If the split is intentional for future differentiation, a brief comment would help readers understand why both exist. Otherwise, callers inside this module (lines 190, 223, 242, 281) could use parse_scss_expression_until directly.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_css_parser/src/syntax/scss/expression/mod.rs` around lines 56 -
62, parse_scss_inner_expression_until is redundant with
parse_scss_expression_until because both simply call
parse_scss_expression_with_options(p, end_ts, false); either remove the
duplicate or add a short explanatory comment. Locate the function
parse_scss_inner_expression_until and either (A) delete it and update internal
callers (the ones currently using parse_scss_inner_expression_until — referenced
near the other callers around the parse_scss_expression_until usage) to call
parse_scss_expression_until directly, or (B) keep it but add a one-line comment
above parse_scss_inner_expression_until explaining the intended future
differentiation, referencing parse_scss_expression_with_options to make the
intent clear. Ensure no external API breakage by only changing callers inside
the module.

103-128: The Pratt parser structure looks solid, but there's no test coverage for degenerate consecutive-operator input like $a + * $c.

The concern about cascading operator consumption is actually correct error recovery behaviour: after bumping the + operator and failing to parse the RHS, the loop re-enters and sees * as the next operator, which legitimately triggers another parsing attempt with its higher precedence. Each missing operand gets a diagnostic via or_add_diagnostic, which is intentional. However, there's currently no explicit test case covering this scenario—consider adding one to the error test suite to ensure the diagnostic output remains user-friendly.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_css_parser/src/syntax/scss/expression/mod.rs` around lines 103 -
128, Add a unit test covering the degenerate consecutive-operator case (e.g. "$a
+ * $c") to the parser error tests to ensure parse_scss_binary_expression
produces readable diagnostics for each missing operand; specifically feed that
input through the same test harness used for other error cases, assert that
scss_binary_precedence-driven recovery yields diagnostics from or_add_diagnostic
tied to expected_component_value for each missing RHS, and verify the final
AST/diagnostic messages remain clear and not cryptic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@crates/biome_css_parser/src/syntax/scss/expression/mod.rs`:
- Around line 56-62: parse_scss_inner_expression_until is redundant with
parse_scss_expression_until because both simply call
parse_scss_expression_with_options(p, end_ts, false); either remove the
duplicate or add a short explanatory comment. Locate the function
parse_scss_inner_expression_until and either (A) delete it and update internal
callers (the ones currently using parse_scss_inner_expression_until — referenced
near the other callers around the parse_scss_expression_until usage) to call
parse_scss_expression_until directly, or (B) keep it but add a one-line comment
above parse_scss_inner_expression_until explaining the intended future
differentiation, referencing parse_scss_expression_with_options to make the
intent clear. Ensure no external API breakage by only changing callers inside
the module.
- Around line 103-128: Add a unit test covering the degenerate
consecutive-operator case (e.g. "$a + * $c") to the parser error tests to ensure
parse_scss_binary_expression produces readable diagnostics for each missing
operand; specifically feed that input through the same test harness used for
other error cases, assert that scss_binary_precedence-driven recovery yields
diagnostics from or_add_diagnostic tied to expected_component_value for each
missing RHS, and verify the final AST/diagnostic messages remain clear and not
cryptic.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2f7d8a9 and 0538e10.

📒 Files selected for processing (3)
  • crates/biome_css_parser/src/syntax/scss/expression/mod.rs
  • crates/biome_css_parser/src/syntax/scss/mod.rs
  • crates/biome_css_parser/src/syntax/value/function.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/biome_css_parser/src/syntax/value/function.rs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/biome_css_parser/src/syntax/scss/expression/mod.rs`:
- Around line 151-154: The rustdoc above the SCSS binary operator precedence
function is a link-only doc comment and should be converted to either a plain
comment or a doctest-style rustdoc; update the triple-slash doc (the comment
starting "Returns the precedence level for the current SCSS binary operator
token.") to a normal line comment (//) or add a minimal doctest code block
showing expected behavior (e.g., an example call and assertion) so it satisfies
the crate's doctest guideline for the precedence-determining function in this
module.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0538e10 and 796df4d.

📒 Files selected for processing (1)
  • crates/biome_css_parser/src/syntax/scss/expression/mod.rs

Comment on lines +151 to +154
/// Returns the precedence level for the current SCSS binary operator token.
///
/// Docs: https://sass-lang.com/documentation/operators/#order-of-operations
#[inline]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Rustdoc here should be doctest-formatted (or be a plain comment).
Guidelines ask for doctest-style rustdoc, but this is a link-only doc comment. Consider switching to a normal comment or adding a minimal doctest block.

💡 Minimal fix: convert to a non-rustdoc comment
-/// Returns the precedence level for the current SCSS binary operator token.
-///
-/// Docs: https://sass-lang.com/documentation/operators/#order-of-operations
+// Returns the precedence level for the current SCSS binary operator token.
+// Docs: https://sass-lang.com/documentation/operators/#order-of-operations
As per coding guidelines "Use doc tests (doctest) format with code blocks in rustdoc comments; ensure assertions pass in tests".
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/// Returns the precedence level for the current SCSS binary operator token.
///
/// Docs: https://sass-lang.com/documentation/operators/#order-of-operations
#[inline]
// Returns the precedence level for the current SCSS binary operator token.
// Docs: https://sass-lang.com/documentation/operators/#order-of-operations
#[inline]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_css_parser/src/syntax/scss/expression/mod.rs` around lines 151 -
154, The rustdoc above the SCSS binary operator precedence function is a
link-only doc comment and should be converted to either a plain comment or a
doctest-style rustdoc; update the triple-slash doc (the comment starting
"Returns the precedence level for the current SCSS binary operator token.") to a
normal line comment (//) or add a minimal doctest code block showing expected
behavior (e.g., an example call and assertion) so it satisfies the crate's
doctest guideline for the precedence-determining function in this module.

@denbezrukov denbezrukov merged commit 9cad748 into main Feb 24, 2026
18 checks passed
@denbezrukov denbezrukov deleted the db/scss-binary branch February 24, 2026 14:03
@Netail Netail added the L-SCSS Language: SCSS label Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Formatter Area: formatter A-Parser Area: parser A-Tooling Area: internal tools L-CSS Language: CSS L-Grit Language: GritQL L-SCSS Language: SCSS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants