libsass
libsass copied to clipboard
No warning for empty selectors with indented syntax
Note that this only happens with sass syntax, not scss syntax.
input.sass
h1
margin-top 1px
Note the missing colon after margin-top.
Actual results
libsass 3.4.3
Empty output. No warnings or errors.
Expected result
ruby sass 3.4.24
WARNING on line 2:
This selector doesn't have any properties and will not be rendered.
(sass):2: Invalid CSS after "margin-top ": expected selector, was "1px" (Sass::SyntaxError)
Spec https://github.com/sass/sass-spec/pull/1139
Can you try the either of the latest releases? 3.4.5 or 3.5.0.beta.3 This would likely be something from https://github.com/mgreter/sass2scss since that is what does the conversion
Thanks for the quick response!
Same behavior on both 3.4.5 and 3.5.0.beta.3.
I tried checking the output of sass2scss, and that indeed appears to be the problem. Without the colon, sass2scss interprets the margin-top 1px as a 2-element css selector... something that would match the following html: <margin-top><1px></1px></margin-top> and thus converts the sass to:
h1 { margin-top 1px {} }
This "correctly" compiles to empty string, because there are no actual declarations under that interpretation.
Ultimately, I would like an error or warning thrown here, like Ruby Sass does. To that end, my first thought is to add missing colon detection to sass2scss. However, it appears that there is no error detection whatsoever in sass2scss; I can't get it to error out no matter what garbage I send it. So perhaps this belongs in libsass, in the form of somehow detecting invalid selectors? Or perhaps adding a "This selector doesn't have any properties and will not be rendered." warning? Thoughts?
I think you're probably right about creating a test in sass-spec then
Similar issues have cropped up before for this behavior. Official ruby sass only emits the "This selector doesn't have any properties and will not be rendered." if the source is indented sass. It does not emit such a message for scss code. Since libsass uses sass2scss to convert from sass to scss, it is not really possible to handle correctly until we carry around a flag what the original source type was, or we implement a sass parser directly in libsass, which will unlikely happen. There is no way for sass2scss to propagate any errors to libsass.
Similar ticket already exists in whishlist => https://github.com/sass/libsass/issues/2229.