Skip to content

apply: take the parsed stylesheet, not the CSS text - #287

Merged
samoht merged 4 commits into
apply-matcher-coveragefrom
apply-error-propagation
Aug 4, 2026
Merged

apply: take the parsed stylesheet, not the CSS text#287
samoht merged 4 commits into
apply-matcher-coveragefrom
apply-error-propagation

Conversation

@samoht

@samoht samoht commented Aug 2, 2026

Copy link
Copy Markdown
Owner

cascade apply deleted a <style> block it could not parse (page shipped unstyled, exit 0) and treated an unreadable supplementary stylesheet as no CSS at all. The root cause is that Css.of_string returns Ok with warnings and an empty sheet for garbage, so no result type on compute could see it: Apply.Make(_).compute now takes ~sheet:Stylesheet.t and the parse stays with the caller (breaking, in CHANGES). The CLI keeps an unusable block verbatim and exits 1, mirroring fmt's #273 contract; style blocks now parse independently as a browser reads them; and result.kept counts rules, not wrapper statements. Stacked on #286.

@samoht
samoht force-pushed the apply-error-propagation branch from ba76bde to f40a4dd Compare August 2, 2026 04:57
@samoht
samoht force-pushed the apply-error-propagation branch from f40a4dd to 7a17fa9 Compare August 2, 2026 05:33
@samoht
samoht force-pushed the apply-error-propagation branch from 7a17fa9 to 14804c2 Compare August 2, 2026 05:45
@samoht
samoht force-pushed the apply-error-propagation branch from 14804c2 to f02301c Compare August 2, 2026 05:59
samoht added 4 commits August 1, 2026 23:02
A <style> block the parser cannot use is deleted from the page and the command
exits 0, so a redirect ships an unstyled page under a green status; an extra
stylesheet that does not parse, or cannot be read at all, is the same shape at
the CLI. The rule count reported alongside is a count of statements, so a @media
block holding three rules reports one.
compute parsed the CSS itself and answered an empty result when the parse
failed, so a caller had no way to tell a stylesheet that did not parse from one
that was empty - both projected onto nothing. Taking a parsed sheet leaves the
parse, and the warnings Css.of_string collects for an input it had to recover,
with the caller. The CLI keeps its current behaviour for now.
Every <style> block was concatenated into one string, parsed once, and deleted
from the page whatever came back, so a block the parser could not use left the
page unstyled under a green exit status. Each block now parses on its own - as a
browser reads them - and one that parses to nothing stays where it is, reported
and gated by an exit 1 the way cascade fmt gates a stylesheet recovery emptied.
A supplementary stylesheet that cannot be read at all is an error too: cmdliner
checks that the path exists, not that it can be read.
The interface calls kept a count of rules and the CLI reports it as one, but a
block at-rule counted once for its wrapper, so a @media holding three rules said
one. The descent goes through Stylesheet.statement_children, whose match is
exhaustive; an at-rule with no statements of its own is itself the one thing
kept and still counts once.
@samoht
samoht force-pushed the apply-error-propagation branch from f02301c to 74e8f41 Compare August 2, 2026 06:02
@samoht
samoht merged commit a26e7e7 into main Aug 4, 2026
5 checks passed
@samoht
samoht deleted the apply-error-propagation branch August 4, 2026 04:21
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.

1 participant