Skip to content

feat(css): add support for SCSS binary expressions in lexer and parser#9343

Merged
denbezrukov merged 4 commits into
mainfrom
db/binary-expr-fix
Mar 5, 2026
Merged

feat(css): add support for SCSS binary expressions in lexer and parser#9343
denbezrukov merged 4 commits into
mainfrom
db/binary-expr-fix

Conversation

@denbezrukov

Copy link
Copy Markdown
Contributor

Summary

SCSS expressions with tight signed numeric tokens were parsed inconsistently in binary contexts
(for example 1+2, 10+10px, 10+10%).

This PR updates SCSS expression parsing so signed numeric-like tokens are handled as binary
operators where appropriate, and adds targeted parser/formatter coverage for these cases,
including unary/binary combinations like 1 - -2, 1 + -3, and 1 + +5.

Test Plan

Ran and passed:

  1. cargo test -p biome_css_parser
  2. cargo test -p biome_css_formatter

@changeset-bot

changeset-bot Bot commented Mar 5, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 1699f0c

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 L-CSS Language: CSS and super languages labels Mar 5, 2026
@coderabbitai

coderabbitai Bot commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b2475824-79f2-4a4b-b56c-f9195206fe03

📥 Commits

Reviewing files that changed from the base of the PR and between 32e1c51 and 1699f0c.

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

Walkthrough

Adds SCSS-specific re-lexing and parser changes to treat leading +/- in expressions as standalone SCSS operators and to re-lex signed numeric literals. A ScssExpression variant was added to CssReLexContext and CssLexer::consume_scss_expression_token was introduced; the parser gains re_lex_signed_numeric_as_scss_operator, report_and_bump_scss_ellipsis, and uses parse_generic_component_value for generic delimiters. A new SCSS test/spec exercising many signed numeric/operator spacing variants was added, and is_at_generic_delimiter visibility was widened.

Possibly related PRs

Suggested labels

L-SCSS

Suggested reviewers

  • ematipico
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding SCSS binary expression support in lexer and parser for handling tight signed numeric tokens.
Description check ✅ Passed The description clearly relates to the changeset, explaining the problem (inconsistent parsing of signed numeric tokens in SCSS), the solution, and test coverage.

✏️ 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/binary-expr-fix

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.

@codspeed-hq

codspeed-hq Bot commented Mar 5, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 7.56%

❌ 1 regressed benchmark
✅ 28 untouched benchmarks
⏩ 187 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
pure_9395922602181450299.css[uncached] 4 ms 4.3 ms -7.56%

Comparing db/binary-expr-fix (1699f0c) with main (20a64c4)

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 coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

271-281: Consider adding a brief doc comment.

The function works correctly, but a short rustdoc comment would clarify its purpose and side-effect nature for future maintainers.

📝 Suggested doc comment
+/// Re-lexes signed numeric tokens (e.g., `+5`, `-10px`) as separate operator
+/// and value tokens when in a binary expression context.
 #[inline]
 fn re_lex_signed_numeric_as_scss_operator(p: &mut CssParser) {

Based on learnings: "Use inline rustdoc documentation for rules, assists, and their options".

🤖 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 271 -
281, Add a short rustdoc comment above the function
re_lex_signed_numeric_as_scss_operator explaining that it checks the current
token for a numeric literal or dimension that begins with '+' or '-' and, if so,
calls p.re_lex with CssReLexContext::ScssExpression to treat the sign as a SCSS
operator (note the side effect of mutating the parser state via
CssParser::re_lex). Keep it concise (one or two sentences), mention the
conditions checked (CSS_NUMBER_LITERAL or is_at_any_dimension) and the mutation
side effect.
🤖 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 271-281: Add a short rustdoc comment above the function
re_lex_signed_numeric_as_scss_operator explaining that it checks the current
token for a numeric literal or dimension that begins with '+' or '-' and, if so,
calls p.re_lex with CssReLexContext::ScssExpression to treat the sign as a SCSS
operator (note the side effect of mutating the parser state via
CssParser::re_lex). Keep it concise (one or two sentences), mention the
conditions checked (CSS_NUMBER_LITERAL or is_at_any_dimension) and the mutation
side effect.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3052522f-8377-4656-a0e4-507a0c26b4f1

📥 Commits

Reviewing files that changed from the base of the PR and between 74f7836 and b3fac2f.

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

@denbezrukov denbezrukov merged commit 4509fc6 into main Mar 5, 2026
15 of 16 checks passed
@denbezrukov denbezrukov deleted the db/binary-expr-fix branch March 5, 2026 17:51
ematipico pushed a commit that referenced this pull request Mar 6, 2026
#9343)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
@Netail Netail added the L-SCSS label Mar 9, 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 L-CSS Language: CSS and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants