Skip to content

feat(css): parse scss interpolated selector names#9486

Merged
denbezrukov merged 3 commits intomainfrom
db/interpolation-1
Mar 16, 2026
Merged

feat(css): parse scss interpolated selector names#9486
denbezrukov merged 3 commits intomainfrom
db/interpolation-1

Conversation

@denbezrukov
Copy link
Contributor

This PR was created with AI assistance (Codex).

Summary

Adds a focused first slice of SCSS selector interpolation support to the CSS parser and
formatter.

  - .#{$name}
  - .#{$name}-bar
  - .foo-#{$name}
  - .foo-#{$name}-bar
  - #app-#{$slot}
  - ##{$id}
  - #{$type}
  - |#{$type}
  - *|#{$type}
  - ns|#{$type}
  - ns|foo-#{$name}
  - #{$type}.class
  - %#{$placeholder}
  - %placeholder-#{$name}

This PR is intentionally scoped to selector names and selector-boundary behavior rather than full
SCSS interpolation support.

Test Plan

  • cargo test -p biome_css_parser
  • cargo test -p biome_css_formatter

@changeset-bot
Copy link

changeset-bot bot commented Mar 15, 2026

⚠️ No Changeset found

Latest commit: 8883da0

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-Linter Area: linter A-Parser Area: parser A-Formatter Area: formatter A-Tooling Area: internal tools L-CSS Language: CSS and super languages L-Grit Language: GritQL labels Mar 15, 2026
@github-actions
Copy link
Contributor

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 53139 53139 0
Passed 51919 51919 0
Failed 1178 1178 0
Panics 42 42 0
Coverage 97.70% 97.70% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 38 38 0
Passed 37 37 0
Failed 1 1 0
Panics 0 0 0
Coverage 97.37% 97.37% 0.00%

markdown/commonmark

Test result main count This PR count Difference
Total 652 652 0
Passed 652 652 0
Failed 0 0 0
Panics 0 0 0
Coverage 100.00% 100.00% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5466 5466 0
Passed 1915 1915 0
Failed 3551 3551 0
Panics 0 0 0
Coverage 35.03% 35.03% 0.00%

ts/babel

Test result main count This PR count Difference
Total 636 636 0
Passed 568 568 0
Failed 68 68 0
Panics 0 0 0
Coverage 89.31% 89.31% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 18875 18875 0
Passed 13014 13014 0
Failed 5860 5860 0
Panics 1 1 0
Coverage 68.95% 68.95% 0.00%

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 15, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks
⏩ 187 skipped benchmarks1


Comparing db/interpolation-1 (8883da0) with main (071d9b9)

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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 15, 2026

Walkthrough

Adds SCSS interpolated identifier support across parser, formatter and codegen. New AST types and unions (ScssInterpolatedIdentifier, part list, AnyCssSelectorIdentifier, AnyCssSelectorCustomIdentifier) are introduced; parser helpers for selector-mode interpolations and selector-aware identifier parsing were added; formatter implementations and wiring for the new nodes were generated; several selector/identifier code paths were tightened to use as_css_identifier() before value_token(); tests for SCSS selector interpolation and error cases were added or updated.

Possibly related PRs

Suggested labels

L-SCSS

Suggested reviewers

  • ematipico
  • dyc3
  • Netail
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarises the main change: adding SCSS interpolated selector name parsing support, which is the core objective of this PR.
Description check ✅ Passed The description is directly related to the changeset, providing a clear summary of SCSS selector interpolation support with concrete examples and 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/interpolation-1
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

CodeRabbit can use Trivy to scan for security misconfigurations and secrets in Infrastructure as Code files.

Add a .trivyignore file to your project to customize which findings Trivy 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.

Actionable comments posted: 2

🤖 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/identifiers/interpolated_identifier.rs`:
- Around line 45-58: The loop that folds fragments into a
ScssInterpolatedIdentifier (starting after first_fragment.precede(p)) only
checks token kinds and therefore glues fragments across comments/trivia; update
the loop that uses is_at_scss_interpolated_identifier(p) and parse_fragment(p)
to first verify there is no intervening leading trivia/comments between the
previous fragment end and the next fragment start (i.e., ensure adjacency)
before calling parse_fragment and extending the list; use the parser
position/offset or trivia APIs available on p to detect leading comments and
bail out (break) if any leading trivia exists so fragments separated by comments
are not merged.

In `@crates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/extend.scss`:
- Line 21: Add a one-line Stylelint suppression immediately before the `@extend`
statement to disable the scss/at-extend-no-missing-placeholder rule for that
line: target the `@extend` .icon-#{$name}; statement and insert a next-line
disable comment for scss/at-extend-no-missing-placeholder so the fixture remains
valid for parser tests without failing lint in CI.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5575d074-cfbc-49f2-89d0-c3f321e31bef

📥 Commits

Reviewing files that changed from the base of the PR and between fe9ff6b and 86ab34b.

⛔ Files ignored due to path filters (12)
  • crates/biome_css_factory/src/generated/node_factory.rs is excluded by !**/generated/**, !**/generated/** and included by **
  • crates/biome_css_factory/src/generated/syntax_factory.rs is excluded by !**/generated/**, !**/generated/** and included by **
  • crates/biome_css_formatter/tests/specs/css/scss/at-rule/extend.scss.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_formatter/tests/specs/css/scss/selector/interpolation.scss.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/error/scss/selector/interpolation.scss.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/extend.scss.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/ok/scss/expression/complex-expressions.scss.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/ok/scss/selector/interpolation.scss.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_syntax/src/generated/kind.rs is excluded by !**/generated/**, !**/generated/** and included by **
  • crates/biome_css_syntax/src/generated/macros.rs is excluded by !**/generated/**, !**/generated/** and included by **
  • crates/biome_css_syntax/src/generated/nodes.rs is excluded by !**/generated/**, !**/generated/** and included by **
  • crates/biome_css_syntax/src/generated/nodes_mut.rs is excluded by !**/generated/**, !**/generated/** and included by **
📒 Files selected for processing (31)
  • crates/biome_css_analyze/src/lint/correctness/no_unknown_type_selector.rs
  • crates/biome_css_formatter/src/css/any/mod.rs
  • crates/biome_css_formatter/src/css/any/selector_custom_identifier.rs
  • crates/biome_css_formatter/src/css/any/selector_identifier.rs
  • crates/biome_css_formatter/src/css/lists/relative_selector_list.rs
  • crates/biome_css_formatter/src/css/lists/selector_list.rs
  • crates/biome_css_formatter/src/css/selectors/complex_selector.rs
  • crates/biome_css_formatter/src/generated.rs
  • crates/biome_css_formatter/src/scss/any/interpolated_identifier_part.rs
  • crates/biome_css_formatter/src/scss/any/mod.rs
  • crates/biome_css_formatter/src/scss/lists/interpolated_identifier_part_list.rs
  • crates/biome_css_formatter/src/scss/lists/mod.rs
  • crates/biome_css_formatter/src/scss/value/interpolated_identifier.rs
  • crates/biome_css_formatter/src/scss/value/mod.rs
  • crates/biome_css_formatter/tests/specs/css/scss/at-rule/extend.scss
  • crates/biome_css_formatter/tests/specs/css/scss/selector/interpolation.scss
  • crates/biome_css_parser/src/syntax/scss/expression/interpolation.rs
  • crates/biome_css_parser/src/syntax/scss/expression/mod.rs
  • crates/biome_css_parser/src/syntax/scss/identifiers/interpolated_identifier.rs
  • crates/biome_css_parser/src/syntax/scss/identifiers/interpolated_selector.rs
  • crates/biome_css_parser/src/syntax/scss/identifiers/mod.rs
  • crates/biome_css_parser/src/syntax/scss/mod.rs
  • crates/biome_css_parser/src/syntax/scss/selector.rs
  • crates/biome_css_parser/src/syntax/selector/mod.rs
  • crates/biome_css_parser/tests/css_test_suite/error/scss/selector/interpolation.scss
  • crates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/extend.scss
  • crates/biome_css_parser/tests/css_test_suite/ok/scss/expression/complex-expressions.scss
  • crates/biome_css_parser/tests/css_test_suite/ok/scss/selector/interpolation.scss
  • crates/biome_grit_patterns/src/grit_target_language/css_target_language/generated_mappings.rs
  • xtask/codegen/css.ungram
  • xtask/codegen/src/css_kinds_src.rs

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.

Actionable comments posted: 1

🤖 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/selector/mod.rs`:
- Around line 544-556: The pseudo-element and pseudo-class parsers should use
the fragment-only parser to ensure they produce a plain CssIdentifier rather
than an ScssInterpolatedIdentifier: replace calls to parse_selector_identifier
with parse_selector_identifier_fragment inside parse_pseudo_element_identifier
and parse_pseudo_class_identifier so they no longer return SCSS interpolation
variants (ScssInterpolatedIdentifier) or AnyCssSelectorCustomIdentifier,
preserving the grammar's requirement of name: CssIdentifier.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 562afba1-e165-465c-bc7b-6952912d27ff

📥 Commits

Reviewing files that changed from the base of the PR and between 86ab34b and 3e7f867.

📒 Files selected for processing (5)
  • crates/biome_css_parser/src/syntax/scss/expression/interpolation.rs
  • crates/biome_css_parser/src/syntax/scss/identifiers/interpolated_selector.rs
  • crates/biome_css_parser/src/syntax/scss/identifiers/mod.rs
  • crates/biome_css_parser/src/syntax/scss/mod.rs
  • crates/biome_css_parser/src/syntax/selector/mod.rs

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.

Actionable comments posted: 3

🤖 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/selector/pseudo_class/identifier.rs`:
- Line 4: The pseudo-class identifier code is calling the plain
parse_selector_identifier_fragment (losing SCSS interpolation support); replace
that call and import with the SCSS-aware identifier parser (the function used
elsewhere for SCSS parsing, e.g., parse_selector_identifier_fragment_scss or the
project’s SCSS-aware variant) so pseudo-class identifiers again accept
interpolation and emit the correct CST shape; update the use line to import the
SCSS-aware function and change the call in identifier.rs (the invocation on line
with parse_selector_identifier_fragment) to that SCSS-aware function.

In `@crates/biome_css_parser/src/syntax/selector/pseudo_element.rs`:
- Around line 7-8: The code currently calls parse_selector_identifier_fragment
for pseudo-element identifiers (referenced as
parse_selector_identifier_fragment) which bypasses SCSS interpolation handling;
update the pseudo-element parsing to use the SCSS-aware parse path (e.g., call
parse_selector or the SCSS-aware selector parser used elsewhere) instead of
parse_selector_identifier_fragment so interpolation tokens are recognized and
recovered correctly (adjust any surrounding token handling like
eat_or_recover_selector_function_close_token and
recover_selector_function_parameter as needed to fit the new parser call).

In
`@crates/biome_css_parser/tests/css_test_suite/ok/scss/selector/interpolation.scss`:
- Around line 33-35: The SCSS rule with selector ".foo-#{$name} #{$second}"
contains an empty block which triggers the block-no-empty rule; add a meaningful
placeholder declaration (for example a harmless property like `/* keep */` is
not allowed as code here, so add a real declaration such as `display: block;` or
another non-breaking property) inside the rule block to avoid an empty rule
while preserving selector intent; update the rule in the test fixture containing
the selector ".foo-#{$name} #{$second}" to include the declaration so the test
no longer trips block-no-empty.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 42fe258c-dfb2-4e9e-83a4-fc18bb2f92a7

📥 Commits

Reviewing files that changed from the base of the PR and between 3e7f867 and 8883da0.

⛔ Files ignored due to path filters (3)
  • crates/biome_css_formatter/tests/specs/css/scss/selector/interpolation.scss.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/error/scss/selector/interpolation.scss.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/ok/scss/selector/interpolation.scss.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (5)
  • crates/biome_css_formatter/tests/specs/css/scss/selector/interpolation.scss
  • crates/biome_css_parser/src/syntax/selector/pseudo_class/identifier.rs
  • crates/biome_css_parser/src/syntax/selector/pseudo_element.rs
  • crates/biome_css_parser/tests/css_test_suite/error/scss/selector/interpolation.scss
  • crates/biome_css_parser/tests/css_test_suite/ok/scss/selector/interpolation.scss
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/biome_css_formatter/tests/specs/css/scss/selector/interpolation.scss

@denbezrukov denbezrukov merged commit 25fd5fd into main Mar 16, 2026
19 checks passed
@denbezrukov denbezrukov deleted the db/interpolation-1 branch March 16, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Formatter Area: formatter A-Linter Area: linter A-Parser Area: parser A-Tooling Area: internal tools L-CSS Language: CSS and super languages L-Grit Language: GritQL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant