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

(Inline) Descendant combinator is not recognised properly #41

Open futursolo opened 2 years ago

futursolo commented 2 years ago

For the following stylesheet:

.class-a.class-b {
    color: red;
}
.class-a .class-b {
    color: blue
}

For inline syntax, the input above yields the following stylesheet:

.class-a.class-b {
    color: red;
}
.class-a.class-b {
    color: blue;
}

After consulting the documentation of proc_macro2, I am not sure what's the best course of action to solve this issue. (I don't think possible to detect spaces between Ident and Punct.)

@WorldSEnder Any ideas?

WorldSEnder commented 2 years ago

Detecting spaces in token-trees is a hard thing to do. I think the best course right now is to heavily document this. A simply workaround without ambiguity (I think) and not having to detect the space is to prefer the following syntax:

.class-a *.class-b {
    color: blue
}

which is actionable and could be implemented to act correctly (possible have to adjust fragment_spacing). Also, in nightly rust, this can be detected. To give another example where also spacing mucks up the current implementation, although I can't think of an actual css that uses it:

prop: ident --ident;
   // ------------- parsed as a single identifier `ident--ident`

Same underlying reason that it's not possible to detect the spacing in stable rust.

futursolo commented 2 years ago

This issue is mitigated in #42.

The proper solution requires https://github.com/rust-lang/rust/issues/54725 to become available in stable Rust.

WorldSEnder commented 1 year ago

Proc macro's source_text has been stabilized, so this might be feasible to implement now. At least recognizing spaces is now no problem any longer.