Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Never output empty blocks #659

Closed
xzyfer opened this issue Nov 19, 2014 · 6 comments · Fixed by #769
Closed

Never output empty blocks #659

xzyfer opened this issue Nov 19, 2014 · 6 comments · Fixed by #769

Comments

@xzyfer
Copy link
Contributor

xzyfer commented Nov 19, 2014

Under some circumstances Libsass will output blocks (selectors) without any declarations i.e.

.my-selector {

}

Specs added sass/sass-spec#199

@KittyGiraudel
Copy link

Do you have any hint about when LibSass happens to behave like this?

@xzyfer
Copy link
Contributor Author

xzyfer commented Dec 11, 2014

In Ruby sass, when a declaration's value is evaluated to null the declaration is not outputted. Libsass follows this behaviour. However when that behaviour produces an empty block, the block is still incorrectly outputted.

Compare these to Ruby Sass:
http://sassmeister.com/gist/40b92fb0a73177ac383b
http://sassmeister.com/gist/9788dfaf2fba2a7428bd

@lunelson
Copy link

I made a test for this—note however, that actually writing null directly in to a declaration still outputs. For this test I had to create a function that returns null, rather than the following which was my first try (however this is an unlikely edge case).

input:

.test {
  out: null;
}

output:

.test {
  out: null; }

@KittyGiraudel
Copy link

This is actually an intended behaviour from Sass. As far as I know, to speed up compilation times Sass does not evaluate all CSS values. It does some kind of quick match to see whether a value should be evaluated as SassScript or not.

While this behaviour leads to an issue where you can actually output prop: null if you explicitly write null as a CSS value, this scenario is very unlikely.

Anyway, this explains the need for a function. If you want to avoid having to declare a function/mixin for this, you can simply wrap null in braces to force Sass to evaluate it:

foo {
  bar: (null);
}

@lunelson
Copy link

Thanks @hugogiraudel that's what I figured ;)

@xzyfer
Copy link
Contributor Author

xzyfer commented Dec 18, 2014

As far as I know, to speed up compilation times Sass does not evaluate all CSS values. It does some kind of quick match to see whether a value should be evaluated as SassScript or not.

@hugogiraudel is correct. I recently added this is the same smarts to Libsass.

For this test I had to create a function that returns null

Both functions that return null and variables with the null value should have this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants