feat(css): add support for SCSS @if, @else, and @while at-rules#9417
feat(css): add support for SCSS @if, @else, and @while at-rules#9417denbezrukov merged 5 commits intomainfrom
@if, @else, and @while at-rules#9417Conversation
|
Parser conformance results onjs/262
jsx/babel
markdown/commonmark
symbols/microsoft
ts/babel
ts/microsoft
|
Merging this PR will not alter performance
Comparing Footnotes
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughAdds SCSS conditional support across the repo: grammar additions (ScssIfAtRule, ScssWhileAtRule, ScssElseClause, AnyScssElseClauseBody) and codegen updates; lexer keyword for Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
crates/biome_css_formatter/src/scss/statements/while_at_rule.rs (1)
8-26: Consider a tiny helper for SCSS control-flow at-rules.This layout now matches
FormatScssIfAtRulealmost byte-for-byte. A shared helper would keep the next control-flow rule from copy-pasting the same spacing logic again.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/biome_css_formatter/src/scss/statements/while_at_rule.rs` around lines 8 - 26, The while at-rule formatting in FormatScssWhileAtRule (fmt_fields using ScssWhileAtRuleFields: while_token, condition, block) duplicates the same layout as FormatScssIfAtRule; extract a small helper function (e.g., format_scss_control_flow_at_rule) that accepts the token, condition and block format elements and writes them with the correct spacing, then call that helper from FormatScssWhileAtRule::fmt_fields and from FormatScssIfAtRule::fmt_fields to remove duplication.crates/biome_css_parser/src/syntax/scss/at_rule/if_at_rule.rs (1)
34-34: Minor style inconsistency with sibling parser.The
while_at_rule.rsimportsWHILE_KWdirectly and usesp.bump(WHILE_KW), whereas here you use theT![if]macro. Both work identically, but for consistency within theat_rulemodule, consider aligning the style.♻️ Optional: Align with while_at_rule.rs style
-use biome_css_syntax::CssSyntaxKind::{self, SCSS_IF_AT_RULE}; +use biome_css_syntax::CssSyntaxKind::{self, IF_KW, SCSS_IF_AT_RULE};- p.bump(T![if]); + p.bump(IF_KW);🤖 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/at_rule/if_at_rule.rs` at line 34, The bump call uses the T![if] macro while sibling parsers use a keyword constant; change p.bump(T![if]) to p.bump(IF_KW) and import IF_KW at the top (mirroring WHILE_KW usage in while_at_rule.rs) so the at_rule module uses the same keyword-constant style; remove the macro usage and ensure IF_KW is available in the scope where p.bump is called.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/biome_css_parser/src/syntax/scss/at_rule/while_at_rule.rs`:
- Around line 31-34: The while-at-rule currently parses the body with
parse_declaration_or_rule_list_block(p) and drops its ParsedSyntax result, which
skips the required-node diagnostic on a missing `{ ... }`; change this to route
the body parse through or_add_diagnostic so the parser will emit/recover as
expected (e.g., call
parse_declaration_or_rule_list_block(p).or_add_diagnostic(p,
<appropriate_error_diag>) similar to how parse_rule(p).or_add_diagnostic(p,
error) is used), keeping the existing condition parse
(parse_scss_expression_until with SCSS_WHILE_CONDITION_END_SET and
expected_scss_expression) and still advancing the token with p.bump(WHILE_KW).
---
Nitpick comments:
In `@crates/biome_css_formatter/src/scss/statements/while_at_rule.rs`:
- Around line 8-26: The while at-rule formatting in FormatScssWhileAtRule
(fmt_fields using ScssWhileAtRuleFields: while_token, condition, block)
duplicates the same layout as FormatScssIfAtRule; extract a small helper
function (e.g., format_scss_control_flow_at_rule) that accepts the token,
condition and block format elements and writes them with the correct spacing,
then call that helper from FormatScssWhileAtRule::fmt_fields and from
FormatScssIfAtRule::fmt_fields to remove duplication.
In `@crates/biome_css_parser/src/syntax/scss/at_rule/if_at_rule.rs`:
- Line 34: The bump call uses the T![if] macro while sibling parsers use a
keyword constant; change p.bump(T![if]) to p.bump(IF_KW) and import IF_KW at the
top (mirroring WHILE_KW usage in while_at_rule.rs) so the at_rule module uses
the same keyword-constant style; remove the macro usage and ensure IF_KW is
available in the scope where p.bump is called.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f2777a32-966a-4ba9-b451-cffc9810719c
⛔ Files ignored due to path filters (15)
crates/biome_css_factory/src/generated/node_factory.rsis excluded by!**/generated/**,!**/generated/**and included by**crates/biome_css_factory/src/generated/syntax_factory.rsis excluded by!**/generated/**,!**/generated/**and included by**crates/biome_css_formatter/tests/specs/css/scss/at-rule/else.scss.snapis excluded by!**/*.snapand included by**crates/biome_css_formatter/tests/specs/css/scss/at-rule/if-else.scss.snapis excluded by!**/*.snapand included by**crates/biome_css_formatter/tests/specs/css/scss/at-rule/while.scss.snapis excluded by!**/*.snapand included by**crates/biome_css_parser/tests/css_test_suite/error/scss/at-rule/else.scss.snapis excluded by!**/*.snapand included by**crates/biome_css_parser/tests/css_test_suite/error/scss/at-rule/if.scss.snapis excluded by!**/*.snapand included by**crates/biome_css_parser/tests/css_test_suite/error/scss/at-rule/while.scss.snapis excluded by!**/*.snapand included by**crates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/else.scss.snapis excluded by!**/*.snapand included by**crates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/if.scss.snapis excluded by!**/*.snapand included by**crates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/while.scss.snapis excluded by!**/*.snapand included by**crates/biome_css_syntax/src/generated/kind.rsis excluded by!**/generated/**,!**/generated/**and included by**crates/biome_css_syntax/src/generated/macros.rsis excluded by!**/generated/**,!**/generated/**and included by**crates/biome_css_syntax/src/generated/nodes.rsis excluded by!**/generated/**,!**/generated/**and included by**crates/biome_css_syntax/src/generated/nodes_mut.rsis excluded by!**/generated/**,!**/generated/**and included by**
📒 Files selected for processing (28)
crates/biome_css_formatter/src/css/any/at_rule.rscrates/biome_css_formatter/src/generated.rscrates/biome_css_formatter/src/scss/any/else_clause_body.rscrates/biome_css_formatter/src/scss/any/mod.rscrates/biome_css_formatter/src/scss/auxiliary/else_clause.rscrates/biome_css_formatter/src/scss/auxiliary/mod.rscrates/biome_css_formatter/src/scss/statements/if_at_rule.rscrates/biome_css_formatter/src/scss/statements/mod.rscrates/biome_css_formatter/src/scss/statements/while_at_rule.rscrates/biome_css_formatter/tests/specs/css/scss/at-rule/else.scsscrates/biome_css_formatter/tests/specs/css/scss/at-rule/if-else.scsscrates/biome_css_formatter/tests/specs/css/scss/at-rule/while.scsscrates/biome_css_parser/src/lexer/mod.rscrates/biome_css_parser/src/syntax/at_rule/mod.rscrates/biome_css_parser/src/syntax/scss/at_rule/else_clause.rscrates/biome_css_parser/src/syntax/scss/at_rule/if_at_rule.rscrates/biome_css_parser/src/syntax/scss/at_rule/mod.rscrates/biome_css_parser/src/syntax/scss/at_rule/while_at_rule.rscrates/biome_css_parser/src/syntax/scss/mod.rscrates/biome_css_parser/tests/css_test_suite/error/scss/at-rule/else.scsscrates/biome_css_parser/tests/css_test_suite/error/scss/at-rule/if.scsscrates/biome_css_parser/tests/css_test_suite/error/scss/at-rule/while.scsscrates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/else.scsscrates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/if.scsscrates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/while.scsscrates/biome_grit_patterns/src/grit_target_language/css_target_language/generated_mappings.rsxtask/codegen/css.ungramxtask/codegen/src/css_kinds_src.rs
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/biome_css_parser/src/syntax/scss/at_rule/while_at_rule.rs (1)
45-48: Consider inlining or returning the result.This wrapper discards the
ParsedSyntaxand adds indirection. Either inline the call at line 35 (matching@if), or change the signature to returnParsedSyntaxso the caller can attach diagnostics.♻️ Option A: Inline (match `@if` pattern)
- parse_scss_while_block(p); + parse_declaration_or_rule_list_block(p);Then remove
parse_scss_while_blockentirely.♻️ Option B: Return result for diagnostic handling
#[inline] -fn parse_scss_while_block(p: &mut CssParser) { - parse_declaration_or_rule_list_block(p); +fn parse_scss_while_block(p: &mut CssParser) -> ParsedSyntax { + parse_declaration_or_rule_list_block(p) }Then at call site:
- parse_scss_while_block(p); + parse_scss_while_block(p).or_add_diagnostic(p, expected_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/scss/at_rule/while_at_rule.rs` around lines 45 - 48, The wrapper parse_scss_while_block currently discards the ParsedSyntax and only delegates to parse_declaration_or_rule_list_block, adding unnecessary indirection; either inline the call where parse_scss_while_block is used (remove parse_scss_while_block entirely to match the `@if` pattern) or change parse_scss_while_block's signature to return ParsedSyntax and forward the result from parse_declaration_or_rule_list_block so callers can attach diagnostics (update all call sites accordingly).
🤖 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/at_rule/while_at_rule.rs`:
- Around line 45-48: The wrapper parse_scss_while_block currently discards the
ParsedSyntax and only delegates to parse_declaration_or_rule_list_block, adding
unnecessary indirection; either inline the call where parse_scss_while_block is
used (remove parse_scss_while_block entirely to match the `@if` pattern) or change
parse_scss_while_block's signature to return ParsedSyntax and forward the result
from parse_declaration_or_rule_list_block so callers can attach diagnostics
(update all call sites accordingly).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2070810c-8a21-4747-b476-612e7dc795f6
⛔ Files ignored due to path filters (1)
crates/biome_css_parser/tests/css_test_suite/error/scss/at-rule/while.scss.snapis excluded by!**/*.snapand included by**
📒 Files selected for processing (2)
crates/biome_css_parser/src/syntax/scss/at_rule/while_at_rule.rscrates/biome_css_parser/tests/css_test_suite/error/scss/at-rule/while.scss
🚧 Files skipped from review as they are similar to previous changes (1)
- crates/biome_css_parser/tests/css_test_suite/error/scss/at-rule/while.scss
Summary
Adds SCSS control-flow at-rule support for
@if,@else, and@while.Biome now parses and formats SCSS control-flow blocks as dedicated SCSS syntax. Chained
@else ifis supported through the@if/@elseclause path, while orphan@elseis still diagnosedand recovered as bogus syntax.
Test Plan
@if,@else, and@whilecargo test -p biome_css_parsercargo test -p biome_css_formatter