Repository navigation
feat(css): typed values weren't written in CSSOM's canonical forms - #98
Merged
Merged
Conversation
A value matched its grammar and was written back in the grammar's order, but not in the shortest form CSSOM gives each property: `scale: 100% 100%` stayed as written, `circle(closest-side)` kept its default, a lone `left` wasn't `left center`. 508 WPT parsing cases failed on that alone, 150 more on rules the specs give in prose, and short-declaration stylesheets typed slower than Lexbor parses them. Canonical forms live in values/canonical.rs, for 65 properties and the types and functions they share; prose restrictions in values/restrict.rs; SVG path data in values/path.rs. Shorthands leave out longhands at their initial values, `expand` splits lists of layers and nested shorthands, and grammars webref lags on are patched in the generator with where each comes from. Commas follow Values 4 §2.6, and sibling-index() and sibling-count() are math functions. For speed: lone keywords are looked up, one-token values skip the matcher, grammars know what token they can start with, the common match shapes need no tree, and property names hash in a few instructions. WPT CSS parsing goes from 13,907 to 14,758 of 14,893, computed values from 10,974 to 11,287 of 12,041.
jamesconwaydev
enabled auto-merge (squash)
November 19, 2026 08:45
jamesconwaydev
added a commit
that referenced
this pull request
Nov 19, 2026
# Conflicts: # README.md
jamesconwaydev
added a commit
that referenced
this pull request
Nov 19, 2026
jamesconwaydev
added a commit
that referenced
this pull request
Nov 19, 2026
* feat(css): @scope, @container, @import and @Property didn't apply 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. * docs: the at-rule count after #98 is 1,141 of 1,345 * docs: ROADMAP's at-rule count too
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
After #91,
parsec_css::valuesmatched every value against its property's grammar and wrote it back in the grammar's order, but not in the shortest form CSSOM gives each property.scale: 100% 100%stayed as it was, where browsers write1.circle(closest-side)kept its default, and a loneleftas a position wasn'tleft center. Of WPT's 14,893 static CSS parsing cases, 986 failed: 508 on canonical forms, 161 on grammars webref is behind on, 150 on rules the specs only give in prose, and 167 on shorthands. Typing every value was also slower than Lexbor's parse on the short-declaration<style>sheets in the bench, 0.70× at worst (#92).Change
All in
crates/parsec-css. There are no new dependencies.values/canonical.rs. There are rules for 65 properties (opacity: 50%as0.5,rotate: 0 1 0 90degasy 90deg,counter-reset: xasx 0,grid-area: a / b / a / basa / b, pluslist-style,mask,line-clamp,animation-range,grid-template,transform-originand the rest). There are also rules for the types and functions they share, wherever those appear: positions,repeat-style,bg-size, basic shapes, transform and filter functions, easing, counters andsymbols(). A shorthand's||group leaves out longhands at their initial values. If that leaves nothing, it writes the first longhand's initial value (text-decoration: solidisnone). Box shorthands collapse repeats at any depth.values/restrict.rs:<custom-ident>can't be:noneas a counter,spanandautoas grid lines,will-changeinwill-change, generic families andrevert-rulein a family name;steps()andsymbols()counts;grid-template-areasrectangles, checked in linear time;flex's unitless zero.values/path.rs.path()strings are parsed by SVG 2's grammar and written as browsers write them. Bad or empty data makespath()invalid.linear-gradient(, red, blue)andcursor: url(x) pointerare invalid.<number>where both a number and a length would do.sibling-index()andsibling-count()are math functions.scripts/properties.js, for places where webref lags its spec. Each patch cites its source:<timeline-range-name>,line-clamp,column-width(whose initial value webref lost),circle()/ellipse(),polygon's radius,<url-set>,light-dark()images, and<single-transition>'s duration.expand:background,mask,transition,animationandanimation-rangelayer by layer;border-radius,grid-area/grid-row/grid-columnandplace-content;margin,paddingandinset, which set only the first side before;mask-borderformaskandborder-imageforborder.sample:font-familyhas a direct parser, tested against the matcher.font,background,mask,grid,animation,transition,clip-path,offset,grid-template-areas,animation-rangeand others.Tests
WPT CSS parsing: 14,758 of 14,893 pass, up from 13,907. Valid values: 9,383 of 9,429. Invalid values: 5,054 of 5,070. Shorthands: 321 of 394. One canonical-form failure is left, and its test disagrees with its neighbours:
image-resolution: snap -8dpcm from-imageis expected in the order written, while every other case expects grammar order. The other 134 failures:repeat()lists;safe normalinalign-items,font-synthesis: oblique-only,quotes: match-parent,image-orientationwithout angles, and others);-webkit-perspectiveand CSS 2's commarect().The wiki's CSS values page lists them all.
WPT computed values: 11,287 of 12,041 pass, up from 10,974, because a computed value is written in the same shortest form. Media queries (1,370 of 1,370) and cascade (104 of 123) are unchanged.
Runner fix: the WPT runner's tolerant colour comparison read
1emas an exponent. It now reads it as a number and a unit, which had failed every colour case withsign(1em - 10px)in it. Shorthand cases also accept a longhand named by its legacy alias.New unit tests: path data, the
font-familyfast path against the matcher, and the sort order of the canonical table.Fuzzing: the extended fuzz target ran clean for five minutes twice, 276,444 inputs and then 233,969 on the final code.
Benchmarks.
cargo run --release --manifest-path bench/Cargo.toml -- css, run twice on an M2 Max, each run started with the one-minute load under 2.1. Typed values, every declaration's value parsed for its property:By sheet, Parsec is ahead in both runs, from 1.04× (the New York Times' and BBC's
<style>) to 1.9× (Font Awesome); before this change the range was 0.70× to 1.17×. The cascade over the 13 pages takes 2.3 s, down from 2.8 s.cargo fmt --all,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspaceandcargo deny checkpass.Closes #92