Skip to content

fix: parse nested boolean groups in @supports and style() into child nodes - #319

Merged
bartveneman merged 1 commit into
mainfrom
claude/nested-supports-conditions
Oct 21, 2026
Merged

bartveneman merged 1 commit into
mainfrom
claude/nested-supports-conditions

Conversation

@bartveneman

Copy link
Copy Markdown
Member

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-position supports() / style() fall back to parse_supports_condition). Both sites now do the same.

Input (via parse_atrule_prelude) Before After
supports: ((display:grid) and (display:flex)) one SupportsQuery, no children SupportsQuery with children SupportsQuery, Operator(and), SupportsQuery
container: style((--a:1) and (--b:2)) ContainerQuery > Function(style), no children Function(style) with children SupportsQuery, Operator(and), SupportsQuery
supports: not ((a:1) or (b:2)) Operator(not) + leaf SupportsQuery same, but the SupportsQuery has structured children

Changes

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 the SupportsQuery.
  • parse_function_condition: the style branch falls back to parse_supports_condition when its content is not a declaration.
  • A small append_nested_condition helper does the recursion and restores the lexer position, because parse_supports_condition moves the shared lexer and callers of parse_function_condition rely on where it ends up.

In src/node-types.ts, SupportsQuery children are now typed SupportsDeclaration | SupportsQuery | PreludeOperator | Function.

Compatibility

Only children are added. .text, .value, .start and .end of the outer nodes are unchanged, and simple declarations keep their shape ((display:grid) is still SupportsQuery > SupportsDeclaration, style(--a:1) is still Function(style) > SupportsDeclaration).

Two things consumers may notice:

  • Code that treats "no children" as "unparsed, handle the raw text myself" now sees children for these nodes.
  • TypeScript code that assumed SupportsQuery.children[0] is a SupportsDeclaration without narrowing may need updating.

Testing

pnpm exec vitest run, tsc --noEmit, oxlint, oxfmt --check and knip pass. New tests cover:

  • a nested @supports group
  • not before a nested group
  • three levels of nesting
  • a function condition (selector()) inside a group
  • @container style((...) and (...)) and style(not (...))
  • regressions for simple declarations
  • offsets: every nested node's .start/.end slices back to its .text, including with comments and newlines

7 of the new tests fail without the fix, and the rest are regression tests for unchanged shapes.


Generated by Claude Code

…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>
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Package Size Increase

📦 Package 📏 Base Size 📏 Source Size 📈 Size Change
@projectwallace/css-parser 47.1 kB 47.2 kB +103 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@6ee3d3d

commit: 6ee3d3d

@bartveneman
bartveneman merged commit 6a12df0 into main Oct 21, 2026
16 checks passed
@bartveneman
bartveneman deleted the claude/nested-supports-conditions branch October 21, 2026 17:00
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