Repository navigation
feat(css): @scope, @container, @import and @property didn't apply - #99
Merged
Merged
Conversation
The cascade read @media, @supports and @layer and dropped every other at-rule: @scope rules never matched, @container ones never held, @import fetched nothing, and @Property registered nothing, so a registered custom property behaved like any other. @Keyframes and @counter-style weren't parsed at all. parsec_css::rules parses @Keyframes, @counter-style and @Property into what they say, and the preludes of @container, @scope and @import. The cascade applies @scope with scoping proximity in its order, evaluates @container's size and style() queries against sizes the caller gives, fetches @imports through the caller's fetch with layer(), scope(), supports() and media, and computes registered properties by their syntax, inheritance and initial value. Styler::at_rules gives the @Keyframes, @counter-style and @Property that win for each name. The WPT cascade runner now also takes css-conditional's container queries, css-properties-values-api, the @counter-style syntax tests and the <template>-based @scope tests: 1,139 of 1,345 pass, from 104 of 123.
# Conflicts: # README.md
jamesconwaydev
enabled auto-merge (squash)
November 19, 2026 08:51
This was referenced Nov 19, 2026
Closed
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.
Problem
The cascade from #94 handled origins, importance,
style="",@layer, specificity, nesting,@mediaand@supports, and dropped every other at-rule.@scoperules never matched, so 13 of the 19 failing static css-cascade WPT cases were@scope.@containernever held.@importfetched nothing.@propertyregistered nothing, so a registered custom property behaved like any other.@keyframesand@counter-styleweren't parsed at all (#95).Change
All in
crates/parsec-css. There are no new dependencies.parsec_css::rules, a new module of parsers. Each one also writes its rule back as CSSOM does.Keyframesholds offsets, includingentry 10%, and declarations, with!importantones left out.CounterStylechecks each descriptor against its grammar and against the spec's prose (noneas a name, range order, additive weights), keeps the rule as CSSOM keeps it, andusable()says whether its system has what it needs.PropertyRuleandSyntaxfollow Properties and Values §5. A missing or invalid descriptor takes its default (*,true).registers()is false where a non-universal syntax has no initial value. An initial value that doesn't match the syntax, or depends on the element, makes the rule invalid.ContainerQueryhandles size features andstyle()queries, with three-valued logic.ScopeBoundshandles the@scopeprelude.Importreads the URL,layer/layer(),scope(),supports()and the media list.@scope: matching follows CSS Cascade 6.:scopeis the root,&is:where(:scope), and declarations straight in the rule apply to the root.to (:scope)scopes nothing.(start), the root is the parent of the<style>; inside a style rule, it's that rule's element.@container:Styler::container_sizes(|el, computed| …)gives each container's size.container-typecovering the axes it asks about. A container withdisplay: noneorcontentscan't be one.style()queries read the container's custom properties.@import:Styler::fetch(|url| …)loads imports.layer(),scope(),supports()and media are honoured.@layerstatements that come before the imports name their layers first.@property: a registered property's computed value is its declared value if that matches the syntax, computed (lengths in px, colours asrgb()). Otherwise it's the parent's or the initial value, depending oninherits.Styler::at_rules()gives the@keyframes,@counter-styleand@propertythat win for each name, with layers counted.@supports at-rule(…)now works.*.style()parsing is capped at a depth of 32.@importfetching the input itself and every container sized.Tests
The WPT cascade runner grew.
scripts/wpt-cascade-cases.jsnow also extracts:css/css-conditional/container-queries,css/css-properties-values-apiandcss/css-counter-styles/counter-style-at-rule;<template>-based tests, the form most@scopetests take;cssRules.length, rule attributes such asconditionText,syntax,inherits,initialValueandconstructor.name, and whethercssTexthas a descriptor;promise_tests, with a<style>'s load event firing.The runner clones templates into the page, fetches
@imports from vendored files ordata:URLs, and sizes containers from their computed pxwidthandheight.WPT results: 1,141 of 1,345 pass, measured with feat(css): typed values weren't written in CSSOM's canonical forms #98 in, up from 104 of 123. By area:
@scopecases that used to fail now pass; the other 3 need shadow DOM or@starting-style.@property: 99 of 122;@counter-style: 200 of 200.Of the 204 failures, 70 are
style()queries (27 of them range syntax), 40 are shadow DOM and pseudo-elements, 23 are@propertyanimation and unit cycles, 20 are container query units, and 19 are containers that layout decides. The known-failures list is checked both ways. Keyframes have no static WPT cases, so unit tests cover them.New unit tests: the
rulesparsers, scope proximity and limits, containers, imports with layers, registered properties, andat_rules.Fuzzing: the fuzz target ran clean for five minutes three times (167,521, 148,288 and 133,166 inputs, the third on the final code).
Unchanged suites: media queries (1,370 of 1,370) and computed values (11,287 of 12,041, with feat(css): typed values weren't written in CSSOM's canonical forms #98).
There's no Lexbor benchmark for this, since Lexbor has none of these at-rules. The cascade bench is unchanged by it: the 13 pages take 2.7 s, against 2.8 s in the README's last run.
cargo fmt --all,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspaceandcargo deny checkpass.Closes #95