fix(parser/css): nested selectors in embedded snippets#9981
fix(parser/css): nested selectors in embedded snippets#9981siketyan merged 1 commit intobiomejs:mainfrom
Conversation
🦋 Changeset detectedLatest commit: c9ed782 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
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 |
Merging this PR will not alter performance
Comparing Footnotes
|
f2e467e to
cc3d742
Compare
WalkthroughAdded 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 Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Co-authored-by: Codex <[email protected]>
cc3d742 to
c9ed782
Compare
There was a problem hiding this comment.
🧹 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::Hintcan surface unrelated hint diagnostics later. This test is parser-focused, soSeverity::Errorkeeps 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
📒 Files selected for processing (4)
.changeset/fix-styled-nested-selectors.mdcrates/biome_css_parser/src/lib.rscrates/biome_css_parser/src/syntax/block/declaration_or_rule_list_block.rscrates/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
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