Skip to content

Parse @scope selectors into SelectorList children - #323

Merged
bartveneman merged 1 commit into
mainfrom
claude/loving-shannon-mlyk62
Oct 21, 2026
Merged

bartveneman merged 1 commit into
mainfrom
claude/loving-shannon-mlyk62

Conversation

@bartveneman

Copy link
Copy Markdown
Member

Summary

This PR adds support for parsing the selector arguments in @scope at-rules into proper SelectorList child nodes, enabling tooling to access the parsed selector structure rather than just the raw text.

Key Changes

  • PreludeSelectorList type enhancement: Changed from a simple Leaf type to a node that can contain a SelectorList child, allowing access to parsed selector structure
  • Selector parsing in @scope prelude: Integrated SelectorParser into AtRulePreludeParser to deep-parse the parenthesized selector arguments of @scope rules
  • Line/column tracking: Implemented accurate line and column offset calculation for selectors within parentheses, accounting for whitespace trimming and newlines
  • Node type registration: Added PRELUDE_SELECTORLIST to the set of node types that can have children
  • Comprehensive test coverage: Added 13 new test cases covering selector parsing, line/column tracking, edge cases (empty parens, invalid selectors), and tree walking

Implementation Details

  • The selector parser is invoked after trimming whitespace from the parenthesized content, with adjusted line/column positions to account for the trimmed prefix
  • Empty parentheses result in a PreludeSelectorList with no children and a null value
  • Invalid selector content is handled gracefully without throwing, preserving the trimmed value for error recovery
  • The walk() function correctly traverses into selector nodes within @scope prelude arguments
  • Clone operations preserve the selector child structure

https://claude.ai/code/session_017DgMj6vDYAFcmet3GUS5n8

PreludeSelectorList nodes now carry a parsed SelectorList child. value, text, start and end are unchanged.
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Package Size Increase

📦 Package 📏 Base Size 📏 Source Size 📈 Size Change
@projectwallace/css-parser 43.8 kB 43.9 kB +169 B

@pkg-pr-new

pkg-pr-new Bot commented Oct 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@projectwallace/css-parser@22acfdc

commit: 22acfdc

@bartveneman
bartveneman merged commit 9c6ec59 into main Oct 21, 2026
16 checks passed
@bartveneman
bartveneman deleted the claude/loving-shannon-mlyk62 branch October 21, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants