Skip to content

Conversation

@bartveneman
Copy link
Member

breaking: add structured prelude property to AT_RULE and STYLE_RULE

BREAKING CHANGES:

  1. AT_RULE.prelude now returns CSSNode|null instead of string

    • Returns AT_RULE_PRELUDE wrapper node containing structured children
    • Access text with .prelude?.text instead of .prelude
    • Raw string still available via .value
    • Returns null for at-rules without structured parsing (@charset, @namespace)
  2. STYLE_RULE.prelude now returns the selector list (CSSNode|null)

    • Returns first child (SELECTOR_LIST node)
    • Access selector text with .prelude?.text
    • Enables walking/traversing selector structure

Changes:

  • Added AT_RULE_PRELUDE (40) node type for wrapping at-rule prelude children
  • Updated prelude getter to support AT_RULE and STYLE_RULE
  • Updated has_prelude getter to support AT_RULE, STYLE_RULE, and DECLARATION
  • Parser now wraps parsed prelude nodes in AT_RULE_PRELUDE wrapper
  • Removed backwards compatibility code from clone()
  • Updated all tests to use .prelude?.text instead of .prelude
  • Updated CLAUDE.md documentation

Aligns with CSSTree API for better interoperability.

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 94.97%. Comparing base (38bf8e5) to head (cf3bfe8).

Files with missing lines Patch % Lines
src/css-node.ts 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #110      +/-   ##
==========================================
- Coverage   94.99%   94.97%   -0.03%     
==========================================
  Files          15       15              
  Lines        2598     2605       +7     
  Branches      674      677       +3     
==========================================
+ Hits         2468     2474       +6     
- Misses        130      131       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bartveneman bartveneman merged commit 5b2ae62 into main Jan 3, 2026
5 checks passed
@bartveneman bartveneman deleted the prelude branch January 3, 2026 19:39
bartveneman added a commit that referenced this pull request Jan 3, 2026
The parser creates a Block node for each Rule and Atrule that contains
nested rules and declarations, providing a consistent tree structure:

- STYLE_RULE: [SELECTOR_LIST (prelude), BLOCK]
- AT_RULE with block: [AT_RULE_PRELUDE (prelude), BLOCK]
- AT_RULE without block: [AT_RULE_PRELUDE (prelude)]

BLOCK nodes contain all nested rules and declarations as children.

Updated API.md to document:
- `.prelude` returns a CSSNode (not text) - use `.prelude.text` for text
- `.block` returns a BLOCK node containing nested rules/declarations
- Examples now use `.prelude.text` and `.prelude?.children`

This clarifies the breaking changes introduced in #110 where `.prelude`
became a structured node instead of text.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@codecov-commenter
Copy link

Bundle Report

Changes will increase total bundle size by 306 bytes (0.22%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
@projectwallace/css-parser-esm 140.88kB 306 bytes (0.22%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: @projectwallace/css-parser-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
css-*.js 306 bytes 16.95kB 1.84%

Files in css-*.js:

  • ./src/css-node.ts → Total Size: 16.09kB

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.

3 participants