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

Give parser ability to automatically collapse repeated property names in a block #6

Open tabatkins opened 8 years ago

tabatkins commented 8 years ago

When you have multiple declarations with the same property name in a single block, CSS automatically collapses them for you, retaining only the last one. While we shouldn't opt the generic parser into this by default (other languages might have a good reason to allow multiple declarations with the same name), it would be nice to give the parser an option to do this for you automatically.

tabatkins commented 8 years ago

Oooh, or better idea: treat declaration values with the same property name as monoids. Default to the List monoid so the multiple values just get collected in an array, allow easily opting into CSS's behavior of using the Last monoid, but also allow just providing a "join" callback to the parser that can implement arbitrary monoidal behavior, like merging properties into a conjoined value. (My InfoTree format I invented for Bikeshed, which is vaguely CSSish, has both of these behaviors, depending on the key - some override with last-wins behavior, others combine in a reasonable way.)

tabatkins commented 8 years ago

(Note that this doesn't need to actually mention the word "monoid" anywhere - the options property can just take either an enum or a function.)