futursolo / stylist-rs

A CSS-in-Rust styling solution for WebAssembly Applications
https://crates.io/crates/stylist
MIT License
370 stars 22 forks source link

Address spacing in combinators #42

Closed WorldSEnder closed 2 years ago

WorldSEnder commented 2 years ago

Closes #41

By inspecting the CSS Selector Spec this identifies tokens that are used at the start or end of <compound-selector>, which signals the intended use of a descendant combinator if no other token is present between them. Expand documentation on this issue and add test cases + ref to upstream tracking of the span API in the rust compiler.

Specifically, * can either start or end a selector, and # can appear at the start. The rest of the tokens like .class or ::before are to be disambiguated by adding a * star selector in front of them to force the spacing.

futursolo commented 2 years ago

I think # can actually appear in places other than the start of a selector (.some-class#some-id)?

Despite that, I think this is actually an excellent workaround!

WorldSEnder commented 2 years ago

I think # can actually appear in places other than the start of a selector (.some-class#some-id)?

Despite that, I think this is actually an excellent workaround!

Have you ever seen that used? I think the first instinct is to write the equivalent but more logical #some-id.some-class, but you're of course right that the above can confusingly have an extra space with this PR.

futursolo commented 2 years ago

Have you ever seen that used?

I actually prefer .some-class#some-id. But I think it's fine to always insert ` before#until we can find a better solution as that can be a relatively rare occasion and having#` alone is much more common.