[csswg-drafts] [css-syntax] Polyfilling CSS (#8699)

plinss has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-syntax] Polyfilling CSS ==
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.)

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/8699 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Monday, 10 April 2023 22:57:00 UTC