Skip to content

fix(parser/css): nested selectors in embedded snippets#9981

Merged
siketyan merged 1 commit intobiomejs:mainfrom
siketyan:omnara/fix-biome-issue-9975
Apr 14, 2026
Merged

fix(parser/css): nested selectors in embedded snippets#9981
siketyan merged 1 commit intobiomejs:mainfrom
siketyan:omnara/fix-biome-issue-9975

Conversation

@siketyan
Copy link
Copy Markdown
Member

@siketyan siketyan commented Apr 14, 2026

Summary

Note

AI Assistance Disclosure: I used the Codex agent to investigate the problem, and create regression tests. All changes and output are reviewed by a human (me).

Fixes #9975

Nested selectors without & (SCSS style) are now correctly parsed inside embedded CSS snippets.

Test Plan

Added a parser test and an integration test.

Docs

N/A

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 14, 2026

🦋 Changeset detected

Latest commit: c9ed782

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

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

@github-actions github-actions Bot added A-Project Area: project A-Parser Area: parser L-CSS Language: CSS and super languages labels Apr 14, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 14, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks
⏩ 227 skipped benchmarks1


Comparing siketyan:omnara/fix-biome-issue-9975 (c9ed782) with main (e0ba71d)

Open in CodSpeed

Footnotes

  1. 227 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.

@siketyan siketyan force-pushed the omnara/fix-biome-issue-9975 branch 2 times, most recently from f2e467e to cc3d742 Compare April 14, 2026 15:13
@siketyan siketyan self-assigned this Apr 14, 2026
@siketyan siketyan changed the title fix(css): parse nested selectors in styled templates fix(parser/css): nested selectors in embedded snippets Apr 14, 2026
@siketyan siketyan changed the title fix(parser/css): nested selectors in embedded snippets fix(parser/css): nested selectors in embedded snippets Apr 14, 2026
@siketyan siketyan requested review from a team April 14, 2026 15:15
@siketyan siketyan marked this pull request as ready for review April 14, 2026 15:15
Copy link
Copy Markdown
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

CI is failing.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 14, 2026

Walkthrough

Added a Changesets entry for a patch release and adjusted the CSS parser to accept nested qualified rules in embedded “styled” snippets by expanding the speculative validation in DeclarationOrRuleList::parse_element to also succeed when the parser is positioned at the block end. New unit and integration tests (CSS parser and workspace server) exercise styled embedded snippets containing nested selectors and assert zero parse diagnostics. No public API or exported declarations were changed.

Suggested reviewers

  • ematipico
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarises the main change: fixing nested selector parsing in embedded CSS snippets, directly addressing the linked issue #9975.
Description check ✅ Passed The description is directly related to the changeset, mentioning the specific issue fixed (#9975) and the test plan, though it's quite brief.
Linked Issues check ✅ Passed The PR successfully addresses issue #9975 by fixing nested selector parsing in embedded snippets without requiring an explicit &, validated by both parser and integration tests.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the nested selector parsing issue: CSS parser logic, regression tests, and a Changesets entry. No extraneous modifications detected.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@siketyan siketyan force-pushed the omnara/fix-biome-issue-9975 branch from cc3d742 to c9ed782 Compare April 14, 2026 16:24
Copy link
Copy Markdown
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/lib.rs (1)

338-341: Consider adding one mixed declaration + nested selector case.

A case like color: red; followed by a nested selector in the same snippet would harden ambiguity coverage with minimal extra cost.

Suggested test-case extension
     for css in [
         "svg:first-of-type {\n  margin-left: 0;\n}\n",
         "div:not(:last-child) {\n  border-bottom: 1px solid black;\n}\n",
+        "color: red;\nsvg:first-of-type {\n  margin-left: 0;\n}\n",
     ] {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_css_parser/src/lib.rs` around lines 338 - 341, The test array of
CSS snippets iterated by the for loop (the "for css in [...]" array) lacks a
mixed declaration-plus-nested-selector case; add an extra string entry that
contains a simple property followed by a nested selector (e.g., "color:
red;\nsvg { fill: blue; }\n" or "color: red;\n  > span { color: blue; }\n") so
the parser is exercised on a declaration immediately followed by a nested rule;
update the array inside the for loop in lib.rs to include this new snippet.
crates/biome_service/src/workspace/server.tests.rs (1)

754-755: Use error-level diagnostics here to reduce future flake.

On Line 754, Severity::Hint can surface unrelated hint diagnostics later. This test is parser-focused, so Severity::Error keeps it tighter.

Small stability tweak
-            diagnostic_level: Severity::Hint,
+            diagnostic_level: Severity::Error,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_service/src/workspace/server.tests.rs` around lines 754 - 755,
The test sets diagnostic_level to Severity::Hint which can surface unrelated
hints and cause flakes; update the test to use Severity::Error instead by
replacing the diagnostic_level value (change Severity::Hint to Severity::Error)
in the test setup (the struct/variable where diagnostic_level and enforce_assist
are defined) so the parser-focused test only considers error-level diagnostics.
🤖 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/lib.rs`:
- Around line 338-341: The test array of CSS snippets iterated by the for loop
(the "for css in [...]" array) lacks a mixed declaration-plus-nested-selector
case; add an extra string entry that contains a simple property followed by a
nested selector (e.g., "color: red;\nsvg { fill: blue; }\n" or "color: red;\n  >
span { color: blue; }\n") so the parser is exercised on a declaration
immediately followed by a nested rule; update the array inside the for loop in
lib.rs to include this new snippet.

In `@crates/biome_service/src/workspace/server.tests.rs`:
- Around line 754-755: The test sets diagnostic_level to Severity::Hint which
can surface unrelated hints and cause flakes; update the test to use
Severity::Error instead by replacing the diagnostic_level value (change
Severity::Hint to Severity::Error) in the test setup (the struct/variable where
diagnostic_level and enforce_assist are defined) so the parser-focused test only
considers error-level diagnostics.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f6837eb4-c15a-4148-9728-4ab0c1ddd7ab

📥 Commits

Reviewing files that changed from the base of the PR and between cc3d742 and c9ed782.

📒 Files selected for processing (4)
  • .changeset/fix-styled-nested-selectors.md
  • crates/biome_css_parser/src/lib.rs
  • crates/biome_css_parser/src/syntax/block/declaration_or_rule_list_block.rs
  • crates/biome_service/src/workspace/server.tests.rs
✅ Files skipped from review due to trivial changes (1)
  • .changeset/fix-styled-nested-selectors.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/biome_css_parser/src/syntax/block/declaration_or_rule_list_block.rs

@siketyan siketyan merged commit 02bd8dd into biomejs:main Apr 14, 2026
29 checks passed
@github-actions github-actions Bot mentioned this pull request Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Parser Area: parser A-Project Area: project L-CSS Language: CSS and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Some CSS rules inside embedded snippets cause parse error

2 participants