feat: improve unknown at-rule parsing with RAW prelude and conditiona…#169
Merged
bartveneman merged 1 commit intomainfrom Mar 10, 2026
Merged
feat: improve unknown at-rule parsing with RAW prelude and conditiona…#169bartveneman merged 1 commit intomainfrom
bartveneman merged 1 commit intomainfrom
Conversation
…l block
Previously, unknown at-rules had two problems:
1. Their prelude was wrapped in AT_RULE_PRELUDE even though the prelude
parser returned no structured children — a RAW node is more accurate.
2. Their block was parsed as rules-only, so declarations like
`@custom { color: red }` were silently dropped.
Prelude: the node type is now decided by what the prelude parser returns.
If `parse_prelude()` produces structured nodes, AT_RULE_PRELUDE is used.
If it returns [] (unknown at-rule), a RAW node is used instead. No
hardcoded list required — the prelude parser already knows what it handles.
Block: the "rules-only" else branch is replaced with the conditional branch
(declarations + rules + at-rules). This is safe for @Keyframes because
`parse_declaration()` returns null for frame selectors without consuming
tokens, producing an identical AST.
Examples:
@Custom prelude; → prelude is RAW (was AT_RULE_PRELUDE)
@Custom { color: red } → block contains DECLARATION (was dropped)
@Custom { .a { } } → block contains STYLE_RULE (unchanged)
@Custom { @media { } } → block contains AT_RULE (was dropped)
@Keyframes foo { from {} } → prelude still AT_RULE_PRELUDE (unchanged)
Removes CONDITIONAL_AT_RULES set and atrule_is_conditional() method
as dead code after the block-parsing simplification.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #169 +/- ##
==========================================
+ Coverage 94.97% 94.99% +0.01%
==========================================
Files 16 16
Lines 2887 2876 -11
Branches 807 804 -3
==========================================
- Hits 2742 2732 -10
+ Misses 145 144 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Bundle ReportChanges will decrease total bundle size by 405 bytes (-0.25%) ⬇️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: @projectwallace/css-parser-esmAssets Changed:
Files in
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…l block
Previously, unknown at-rules had two problems:
@custom { color: red }were silently dropped.Prelude: the node type is now decided by what the prelude parser returns. If
parse_prelude()produces structured nodes, AT_RULE_PRELUDE is used. If it returns [] (unknown at-rule), a RAW node is used instead. No hardcoded list required — the prelude parser already knows what it handles.Block: the "rules-only" else branch is replaced with the conditional branch (declarations + rules + at-rules). This is safe for @Keyframes because
parse_declaration()returns null for frame selectors without consuming tokens, producing an identical AST.Examples:
@Custom prelude; → prelude is RAW (was AT_RULE_PRELUDE)
@Custom { color: red } → block contains DECLARATION (was dropped)
@Custom { .a { } } → block contains STYLE_RULE (unchanged)
@Custom { @media { } } → block contains AT_RULE (was dropped)
@Keyframes foo { from {} } → prelude still AT_RULE_PRELUDE (unchanged)
Removes CONDITIONAL_AT_RULES set and atrule_is_conditional() method as dead code after the block-parsing simplification.