Skip to content

feat!: wrap @import layer() and supports() in a Function node - #318

Merged
bartveneman merged 6 commits into
mainfrom
claude/sharp-thompson-4ueybv
Oct 21, 2026
Merged

bartveneman merged 6 commits into
mainfrom
claude/sharp-thompson-4ueybv

Conversation

@bartveneman

@bartveneman bartveneman commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Addresses #195. In an @import prelude, layer(...) and supports(...) are now Function nodes instead of LayerName / SupportsQuery nodes.

Source Before After
layer(a.b) LayerName{name='a.b'} Function{name='layer'} > LayerName{name='a.b'}
layer() LayerName{name=''} Function{name='layer'} without children
layer LayerName{name=''} unchanged
supports(display: grid) SupportsQuery > SupportsDeclaration Function{name='supports'} > SupportsQuery > SupportsDeclaration
supports((a) and (b)) SupportsQuery (raw value only) Function{name='supports'} with the same flat children as an @supports prelude

Parentheses ownership

  • The Function owns the outer supports( and ).
  • A SupportsQuery only owns parentheses that are present in the source: paren-less inside supports(display: grid), with its own (…) in supports((a) and (b)) and in @supports.

Breaking change

Consumers matching LAYER_NAME / SUPPORTS_QUERY directly in an @import prelude must now look inside the Function child. @layer and @supports preludes are unchanged, and no LayerList node was added. LayerName types are unchanged. The Function child union now includes LayerName.

Migration

Who is affected: anyone who walks an @import prelude and matches LAYER_NAME or SUPPORTS_QUERY on its direct children. @layer and @supports preludes are unchanged.

Shapes in detail

Source Before After
layer(a.b) Layer name='a.b', text='layer(a.b)' Function name='layer', value='a.b', with a child Layer name='a.b', text='a.b'
layer() Layer name='' Function name='layer', no children
layer (bare) Layer name='' unchanged
supports(display: grid) SupportsQuery value='display: grid', text='supports(display: grid)', child SupportsDeclaration Function name='supports', value='display: grid', with a child SupportsQuery text='display: grid', which has the child SupportsDeclaration
supports((a: b) and (c: d)) SupportsQuery with only a raw value, no children Function name='supports' with the same children an @supports (a: b) and (c: d) prelude has: SupportsQuery, Operator, SupportsQuery

Code changes

// Before
for (const node of prelude.children) {
	if (node.type === LAYER_NAME) {
		use(node.name) // 'test.me'
	}
	if (node.type === SUPPORTS_QUERY) {
		use(node.value) // 'display: grid'
	}
}

// After
for (const node of prelude.children) {
	if (node.type === FUNCTION && node.name === 'layer') {
		const layer = node.first_child // null for layer()
		use(layer?.name) // 'test.me'
	} else if (node.type === LAYER_NAME) {
		// bare `layer` (name is '')
	}
	if (node.type === FUNCTION && node.name === 'supports') {
		use(node.value) // 'display: grid' (raw text inside the parentheses)
		const query = node.first_child // SupportsQuery, or the condition's first node
	}
}

Things to watch for:

  • Bare layer: it is still a LayerName at the top level with name === ''. Only layer(…) is wrapped, so handle both.
  • layer(): it has no children, so first_child is null.
  • supports(): its children are either a single SupportsQuery or the compound condition nodes. Don't assume a particular child type.
  • Function types: Function's child union now includes LayerName, so node.first_child narrows correctly.
  • No new node types: no LayerList or other node type was added, and node type numbers are unchanged.

Testing

pnpm exec vitest run, tsc --noEmit, oxlint, oxfmt --check and knip pass. Tests were updated to the new shapes, with added cases for layer(), empty supports() and compound supports() conditions.


Generated by Claude Code

claude and others added 3 commits October 21, 2026 14:52
BREAKING CHANGE: in an `@import` prelude, `layer(name)` and `supports(...)` are
now `Function` nodes instead of `LayerName` / `SupportsQuery` nodes.

- `layer(a.b)`   -> Function{name='layer'} > LayerName{name='a.b'}
- `layer()`      -> Function{name='layer'} without children
- `layer`        -> LayerName (unchanged, name='')
- `supports(d: g)` -> Function{name='supports'} > SupportsQuery > SupportsDeclaration
- `supports((a) and (b))` -> Function{name='supports'} with the same flat
  children as an `@supports` prelude

The Function owns the surrounding parentheses; a SupportsQuery only owns
parentheses that are present in the source.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Package Size Increase

📦 Package 📏 Base Size 📏 Source Size 📈 Size Change
@projectwallace/css-parser 47.2 kB 47.4 kB +149 B

Copy link
Copy Markdown
Member Author

The Publish check (pkg-pr-new publish --commentWithSha) is failing, and it isn't caused by this PR's changes.

  • Error: Check failed (404): There is no workflow defined for <id>, returned by the pkg-pr-new service. The id differs on each run.
  • Reproduces: it failed on every commit of this PR, and again on one re-run of the failed job.
  • Also red on the base branch: the Publish Any Commit run on main at c5257a8 (14:30 today) failed the same way, while the previous main run at 0c9c576 (12:13) passed.
  • Fix: none that can be made in this PR. It looks like the pkg-pr-new app or service side (the workflow registration), not the repo code.

Everything this PR touches is green: Build, Lint, Lint unused code, Unit tests, Check types, Check permissions and Diff dependencies. I'm leaving Publish as is and keeping the PR watched.


Generated by Claude Code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@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@60af53b

commit: 60af53b

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@bartveneman
bartveneman force-pushed the claude/sharp-thompson-4ueybv branch from 3150999 to 615f813 Compare October 21, 2026 16:52
@bartveneman
bartveneman merged commit 41a2d20 into main Oct 21, 2026
16 checks passed
@bartveneman
bartveneman deleted the claude/sharp-thompson-4ueybv branch October 21, 2026 17:12
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