Repository navigation
fix: parse nested boolean groups in @supports and style() into child nodes - #319
Merged
Merged
Conversation
…nodes A parenthesized group that is not a single `(property: value)` declaration, such as `((a: 1) and (b: 2))`, was a leaf SupportsQuery with no children. `style((--a: 1) and (--b: 2))` was a leaf Function. Both now hold the same flat condition nodes (SupportsQuery / Operator / Function) as an `@supports` prelude, matching value-position `supports()`/`style()`. Only children are added: text, value, start and end of the outer nodes are unchanged, and simple declarations keep their existing shape. `SupportsQuery` children are now typed `SupportsDeclaration | SupportsQuery | PreludeOperator | Function`. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
|
| 📦 Package | 📏 Base Size | 📏 Source Size | 📈 Size Change |
|---|---|---|---|
| @projectwallace/css-parser | 47.1 kB | 47.2 kB | +103 B |
commit: |
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.
Summary
Nested boolean conditions came back as a leaf node with no children, which is inconsistent with the places that already parse them (
@import supports(...)and value-positionsupports()/style()fall back toparse_supports_condition). Both sites now do the same.parse_atrule_prelude)supports:((display:grid) and (display:flex))SupportsQuery, no childrenSupportsQuerywith childrenSupportsQuery,Operator(and),SupportsQuerycontainer:style((--a:1) and (--b:2))ContainerQuery > Function(style), no childrenFunction(style)with childrenSupportsQuery,Operator(and),SupportsQuerysupports:not ((a:1) or (b:2))Operator(not)+ leafSupportsQuerySupportsQueryhas structured childrenChanges
In
src/parse-condition.ts:parse_supports_condition: a paren group with no depth-0 colon now recurses and attaches the result as children of theSupportsQuery.parse_function_condition: thestylebranch falls back toparse_supports_conditionwhen its content is not a declaration.append_nested_conditionhelper does the recursion and restores the lexer position, becauseparse_supports_conditionmoves the shared lexer and callers ofparse_function_conditionrely on where it ends up.In
src/node-types.ts,SupportsQuerychildren are now typedSupportsDeclaration | SupportsQuery | PreludeOperator | Function.Compatibility
Only children are added.
.text,.value,.startand.endof the outer nodes are unchanged, and simple declarations keep their shape ((display:grid)is stillSupportsQuery > SupportsDeclaration,style(--a:1)is stillFunction(style) > SupportsDeclaration).Two things consumers may notice:
SupportsQuery.children[0]is aSupportsDeclarationwithout narrowing may need updating.Testing
pnpm exec vitest run,tsc --noEmit,oxlint,oxfmt --checkandknippass. New tests cover:@supportsgroupnotbefore a nested groupselector()) inside a group@container style((...) and (...))andstyle(not (...)).start/.endslices back to its.text, including with comments and newlines7 of the new tests fail without the fix, and the rest are regression tests for unchanged shapes.
Generated by Claude Code