Skip to content

feat(css): improve scss declaration modifier recovery#9352

Merged
denbezrukov merged 3 commits intomainfrom
db/better-recovery-scss
Mar 6, 2026
Merged

feat(css): improve scss declaration modifier recovery#9352
denbezrukov merged 3 commits intomainfrom
db/better-recovery-scss

Conversation

@denbezrukov
Copy link
Contributor

Summary

This PR improves SCSS variable declaration modifier recovery in the CSS parser. The changes enable better error recovery when parsing malformed SCSS variable modifiers, allowing the parser to continue parsing subsequent valid modifiers even after encountering invalid tokens.

Test Plan

cargo test -p biome_css_parser

Docs

@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

⚠️ No Changeset found

Latest commit: 43246e5

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 L-CSS Language: CSS labels Mar 5, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2026

Walkthrough

Reworks SCSS variable declaration parsing by introducing a dedicated modifier parsing workflow and recovery logic. Adds token sets and diagnostics for modifier handling, implements ScssVariableModifierList with end-of-list detection, replaces direct list parsing with parse_scss_variable_modifiers, and adds recovery for malformed/trailing modifier sequences (including a specific diagnostic for disallowed !important). Multiple SCSS tests were added to exercise duplicate-modifier recovery, missing-semicolon recovery, missing values, and namespace/selector boundary cases.

Possibly related PRs

Suggested labels

L-SCSS

Suggested reviewers

  • denbezrukov
  • ematipico
  • dyc3
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarises the main change—improving SCSS variable declaration modifier recovery in the CSS parser.
Description check ✅ Passed The description directly relates to the changeset, explaining the improvements to SCSS modifier error recovery and providing a clear test plan.

✏️ 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/better-recovery-scss

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
Copy link

codspeed-hq bot commented Mar 5, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks
⏩ 187 skipped benchmarks1


Comparing db/better-recovery-scss (43246e5) with main (cb4d7d7)

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.

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/declaration/variable.rs (2)

159-161: Widen the !important error span to cover both tokens.

Right now the range is captured after bumping !, so diagnostics typically underline only important. Including ! as well would make the message match what users see.

Also applies to: 172-177

🤖 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/declaration/variable.rs` around lines
159 - 161, The diagnostic range for the `!important` error is captured after
consuming/bumping tokens, so the span excludes the leading `!`; update both
places where you call p.error(important_modifier_not_allowed(p, p.cur_range()))
followed by p.bump(T![important]) (and the other similar block) to capture the
range before consuming: call let span = p.cur_range() (or otherwise compute the
span that includes the `!` token) and pass that span into
important_modifier_not_allowed when calling p.error, then proceed to bump the
tokens (p.bump(T![bang]) / p.bump(T![important]) as needed) so the error
underline covers both `!` and `important`.

109-112: Recovered modifiers placed outside the modifier list reduce accessor convenience.

Line 110 finalises SCSS_VARIABLE_MODIFIER_LIST before recover_scss_variable_modifier_tail() runs on line 111. Recovered modifiers parsed in the tail loop become sibling nodes rather than list children, so callers using declaration.modifiers() will miss them. This weakens the API ergonomics for traversing all modifiers in well-formed declarations that recover from malformed tokens.

Consider incorporating recovered modifiers into the list marker's scope during recovery to preserve CST structure coherence.

🤖 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/declaration/variable.rs` around lines
109 - 112, The recovered modifiers are being finalized outside the
SCSS_VARIABLE_MODIFIER_LIST because ScssVariableModifierList.parse_list(p)
completes before recover_scss_variable_modifier_tail(p) runs; change
parse_scss_variable_modifiers so recovery happens while the list marker is still
open — either call recover_scss_variable_modifier_tail from inside
ScssVariableModifierList.parse_list or move the list finalization to after
recovery so recovered nodes become children of SCSS_VARIABLE_MODIFIER_LIST and
remain visible to callers using declaration.modifiers().
🤖 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/declaration/variable.rs`:
- Around line 159-161: The diagnostic range for the `!important` error is
captured after consuming/bumping tokens, so the span excludes the leading `!`;
update both places where you call p.error(important_modifier_not_allowed(p,
p.cur_range())) followed by p.bump(T![important]) (and the other similar block)
to capture the range before consuming: call let span = p.cur_range() (or
otherwise compute the span that includes the `!` token) and pass that span into
important_modifier_not_allowed when calling p.error, then proceed to bump the
tokens (p.bump(T![bang]) / p.bump(T![important]) as needed) so the error
underline covers both `!` and `important`.
- Around line 109-112: The recovered modifiers are being finalized outside the
SCSS_VARIABLE_MODIFIER_LIST because ScssVariableModifierList.parse_list(p)
completes before recover_scss_variable_modifier_tail(p) runs; change
parse_scss_variable_modifiers so recovery happens while the list marker is still
open — either call recover_scss_variable_modifier_tail from inside
ScssVariableModifierList.parse_list or move the list finalization to after
recovery so recovered nodes become children of SCSS_VARIABLE_MODIFIER_LIST and
remain visible to callers using declaration.modifiers().

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8b198f25-a84b-4140-9410-e8b267a8e67e

📥 Commits

Reviewing files that changed from the base of the PR and between 02fc474 and 43246e5.

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

@denbezrukov denbezrukov merged commit 104c684 into main Mar 6, 2026
16 checks passed
@denbezrukov denbezrukov deleted the db/better-recovery-scss branch March 6, 2026 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Parser Area: parser L-CSS Language: CSS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants