fix(parser/css): parse conditional block correctly inside embedded snippets#9966
fix(parser/css): parse conditional block correctly inside embedded snippets#9966siketyan merged 1 commit intobiomejs:mainfrom
Conversation
…ippets Co-authored-by: Codex <noreply@openai.com>
🦋 Changeset detectedLatest commit: 6fbd0b6 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 |
WalkthroughThis pull request addresses issue 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/biome_css_parser/src/syntax/block/conditional_block.rs (1)
22-24: Keep the rustdoc aligned with the new branch condition.The docs above still describe only nesting-block state, but Line 23 now also depends on styled embedding context. Worth updating to avoid future head-scratching.
Suggested doc tweak
-/// If the current state of the parser indicates that it's inside a nesting block (e.g., inside a style rule), -/// this function parses the content as a declaration or rule list block. Otherwise, it parses the content -/// as a rule block. +/// If the parser is inside a nesting block (e.g., inside a style rule), or if the source is an embedded +/// styled snippet, this function parses the content as a declaration-or-rule list block. +/// Otherwise, it parses the content as a rule block.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/biome_css_parser/src/syntax/block/conditional_block.rs` around lines 22 - 24, Update the rustdoc above the conditional in conditional_block.rs to reflect that the branch now fires not only when p.state().is_nesting_block is true but also when the source embedding kind is styled (p.source_type.as_embedding_kind() matches EmbeddingKind::Styled); edit the doc text to mention both conditions (nesting-block state and styled embedding context) and, if present, adjust any examples or notes to show the styled-embedding case alongside the nesting-block case.
🤖 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/block/conditional_block.rs`:
- Around line 22-24: Update the rustdoc above the conditional in
conditional_block.rs to reflect that the branch now fires not only when
p.state().is_nesting_block is true but also when the source embedding kind is
styled (p.source_type.as_embedding_kind() matches EmbeddingKind::Styled); edit
the doc text to mention both conditions (nesting-block state and styled
embedding context) and, if present, adjust any examples or notes to show the
styled-embedding case alongside the nesting-block case.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8ff06353-2838-40ff-9609-333dabbca8bb
📒 Files selected for processing (3)
.changeset/fast-zebras-move.mdcrates/biome_css_parser/src/syntax/block/conditional_block.rscrates/biome_service/src/workspace/server.tests.rs
Merging this PR will not alter performance
Comparing Footnotes
|
Summary
Note
AI Assistance Disclosure: I used the Codex agent to investigate the problem, create a regression test, and draft the PR description. All changes and output are reviewed by a human (me).
Fixes #9113
Embedded CSS snippets are parsed as
CSS_SNIPPET_ROOT, which allows top-level declarations, but nested conditional blocks like@media { ... }were still using the regularparse_rule_block()path unless the parser was already inside a nesting block. As a result, declarations such asheight: 40px;inside@mediawere misparsed as selectors.This pull request fixes the parser to treat conditional blocks in embedded snippets the same way as nesting blocks, and parse them with
parse_declaration_or_rule_list_block(). This allows declarations inside@mediawithin CSS-in-JS snippets to be parsed correctly.Test Plan
Added a snapshot test.
Docs
N/A