[css-syntax] Polyfilling CSS
Nobody has claimed this yet.
- Dominant language
- Bikeshed
- Stars
- 4.9k
- Forks
- 816
- PR merge metrics
- PR metrics pending
Description
While CSS generally depends on progressive enhancement, we sometime add features that are an all-or-nothing buy-in (mostly), such as nesting, scoping, and cascade layers.
In an ideal world, we should be able to polyfill the CSS parser to allow older clients to consume newer features. For example, a nesting polyfill could de-sugar nested rules and produce a functional equivalent. Currently a polyfill would have to replace the CSS parser entirely.
I wanted to raise an issue to hopefully start a discussion around what that might look like in a form that might even be doable in the short term.
One thought is having the ability to register a JS worklet callback that handles a list of tokens when the error recovery algorithm kicks in. (Ideally those would be token objects, but an early version could just be strings.) The callback would also need to have the context of where the error took place, e.g. the rule for something skipped in a declaration block so it could inject other content with equivalent functionality.
A different approach could be to expose an API that consumes a stylesheet and produces just a token stream. A polyfill could transform the tokens and pass them on the to regular parser.
(This is really more of a Houdini type of issue, but since that TF seems somewhat dormant these days I thought I'd start here, feel free to move this issue. I'm also aware of the prior work on the parser API, but I'm hoping for something lightweight here that can be shipped soon and later developed into the full parser API.)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files, tests, or entry points are identified. Start by reviewing the proposed worklet callback and stylesheet-to-token-stream approaches, along with the referenced parser API work. Done would require an agreed, implementable proposal for CSS parser polyfilling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- css
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100