WICG / css-parser-api

This is the repo where the CSS Houdini parser API will be worked on
Other
71 stars 14 forks source link

CSSParse shouldn't be a global object #3

Open FremyCompany opened 8 years ago

FremyCompany commented 8 years ago

You should be able to create various instances with various options and move from there.

Instances should have a way to decide if a declaration is valid or not; so that the styleMap works. If your polyfill recognizes "#ff00ff" but not "#ff00ffff" the second declaration should be ignored in this case ```--color: #ff00ff; --color: #ff00ffff". Well the example is dumb but you got the idea.

tabatkins commented 8 years ago

Parsing "as CSS" should just parse as CSS; no need for options that I can see.

Parsing "as generic CSS-ish syntax" shouldn't do any of that error-handling. Blocks containing declarations should just produce a list of declarations, not a StyleMap. Your example should produce a block containing an array of two declarations, each with a name of "--color" and a value that's an array holding a CSSHashToken{value:"ff00ff"} or similar.

It might be reasonable to be able to pass some options to the generic parser to opt into some things, like last-wins semantics in declarations.

FremyCompany commented 8 years ago

My point was that styleMap.get("--background") should be able to be configured somehow so that the last valid declaration wins, aka you get a callback where you can say what is valid for --background (or any other property).

If there is like you mention a mode that does not assume last-win, you can disregard this feedback, this behavior can be implemented in the JS-side.