basro / stylance-rs

Scoped CSS style imports for rust.
MIT License
43 stars 4 forks source link

@container / @extend classes are not being resolved correctly #1

Closed s1n7ax closed 1 month ago

s1n7ax commented 1 month ago

classes used in @media quries are correcly being resolved.

image

However, @extend & @container classes are not resolved and it's using the literal text in the original class name.

image

basro commented 1 month ago

I've released 0.4.0 with the @container query support PR merged.

s1n7ax commented 1 month ago

@basro Hi, When pixel amount is used, container parsing works but when variable is used, parsing fails.

image

  @container (min-width: #{$screen-md}) {
    & {
      background-color: green;
      padding-left: 10rem;
      padding-right: 10rem;
    }
  }
basro commented 1 month ago

Would be better to open a separate issue for that. I'll see if I can fix it.

basro commented 1 month ago

The problem comes from the sass interpolation syntax #{...} which I must admit didn't know existed.

Seems like sass lets you use variables in @media queries, but for @container it wont automatically replace them so interpolation needs to be used...

s1n7ax commented 1 month ago

@basro Might be a complete re-right but treesitter would be a better approach. I have no clue how to communicate with the c parser from rust though.

https://github.com/serenadeai/tree-sitter-scss

image

basro commented 1 month ago

For now I've released v0.5.0 which will accept sass interpolation syntax in many places. Probably not all places where sass accepts it, but it will at least accept your example without issues.

Using tree sitter might make sense but as you noted, it's a rewrite and is not worth it for me at the moment. Also, the small custom parser in stylance probably has an advantage when it comes to compilation times that have to be weighted in. (Haven't measured though, just guessing)

basro commented 1 month ago

I'll close this issue. Scoped classes in @extend remains unsupported, if you have interest in that feature feel free to open an issue that is specifically about that.