Skip to content

feat(css): @scope, @container, @import and @property didn't apply - #99

Merged
jamesconwaydev merged 4 commits into
mainfrom
css-at-rules
Nov 19, 2026
Merged

jamesconwaydev merged 4 commits into
mainfrom
css-at-rules

Conversation

@jamesconwaydev

@jamesconwaydev jamesconwaydev commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The cascade from #94 handled origins, importance, style="", @layer, specificity, nesting, @media and @supports, and dropped every other at-rule. @scope rules never matched, so 13 of the 19 failing static css-cascade WPT cases were @scope. @container never held. @import fetched nothing. @property registered nothing, so a registered custom property behaved like any other. @keyframes and @counter-style weren'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.
    • Keyframes holds offsets, including entry 10%, and declarations, with !important ones left out.
    • CounterStyle checks each descriptor against its grammar and against the spec's prose (none as a name, range order, additive weights), keeps the rule as CSSOM keeps it, and usable() says whether its system has what it needs.
    • PropertyRule and Syntax follow 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.
    • ContainerQuery handles size features and style() queries, with three-valued logic.
    • ScopeBounds handles the @scope prelude.
    • Import reads the URL, layer/layer(), scope(), supports() and the media list.
  • @scope: matching follows CSS Cascade 6.
    • Scoping proximity is a new step in the cascade order, between specificity and order of appearance.
    • :scope is the root, & is :where(:scope), and declarations straight in the rule apply to the root.
    • Limits work, and to (:scope) scopes nothing.
    • Without a (start), the root is the parent of the <style>; inside a style rule, it's that rule's element.
    • Each element's roots extend its parent's, computed top-down and cached, so nothing recurses on document depth. Scopes nest at most eight deep.
  • @container: Styler::container_sizes(|el, computed| …) gives each container's size.
    • A query picks the nearest container with the right name and a container-type covering the axes it asks about. A container with display: none or contents can't be one.
    • style() queries read the container's custom properties.
  • @import: Styler::fetch(|url| …) loads imports.
    • layer(), scope(), supports() and media are honoured.
    • The import's layer is named even if the fetch gives nothing.
    • @layer statements that come before the imports name their layers first.
    • Imports nest at most 16 deep, and one styling follows at most 256 of them.
  • @property: a registered property's computed value is its declared value if that matches the syntax, computed (lengths in px, colours as rgb()). Otherwise it's the parent's or the initial value, depending on inherits.
  • Styler::at_rules() gives the @keyframes, @counter-style and @property that win for each name, with layers counted. @supports at-rule(…) now works.
  • Hostile input:
    • Syntax strings are interned with a cap of 4,096, past which a new syntax acts as *.
    • style() parsing is capped at a depth of 32.
    • The fuzz target now parses every at-rule as each kind and writes it back, evaluates container queries, and cascades with every @import fetching the input itself and every container sized.

Tests

  • The WPT cascade runner grew. scripts/wpt-cascade-cases.js now also extracts:

    • css/css-conditional/container-queries, css/css-properties-values-api and css/css-counter-styles/counter-style-at-rule;
    • <template>-based tests, the form most @scope tests take;
    • CSSOM probes: cssRules.length, rule attributes such as conditionText, syntax, inherits, initialValue and constructor.name, and whether cssText has a descriptor;
    • the tests' own helper scripts;
    • promise_tests, with a <style>'s load event firing.

    The runner clones templates into the page, fetches @imports from vendored files or data: URLs, and sizes containers from their computed px width and height.

  • 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:

    • css-cascade: 281 of 293, up from 104. 10 of the 13 @scope cases that used to fail now pass; the other 3 need shadow DOM or @starting-style.
    • container queries: 561 of 730;
    • @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 @property animation 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 rules parsers, scope proximity and limits, containers, imports with layers, registered properties, and at_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 --workspace and cargo deny check pass.

Closes #95

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.
@jamesconwaydev
jamesconwaydev enabled auto-merge (squash) November 19, 2026 08:51
@jamesconwaydev
jamesconwaydev merged commit ad9c6fa into main Nov 19, 2026
33 checks passed
@jamesconwaydev
jamesconwaydev deleted the css-at-rules branch November 19, 2026 08:53
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.

The cascade's missing at-rules: @container, @scope, @property, @keyframes, @counter-style, @import

1 participant