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

variables losing zeros #1140

Closed
rodneyrehm opened this issue Apr 27, 2015 · 15 comments · Fixed by #1152
Closed

variables losing zeros #1140

rodneyrehm opened this issue Apr 27, 2015 · 15 comments · Fixed by #1152
Assignees
Milestone

Comments

@rodneyrehm
Copy link
Contributor

Sorry for the weird title, I'm not sure how to even describe this properly.

given the input

$line-height: 20px; div {line-height: $line-height;}

I get the output

div {
  line-height: 2px; }

note how 20px turned into 2px. I see the same behavior for 0.1px turning into px.


I've tracked the issue down to sass_option_set_precision(ctx_opt, 0); being the culprit. Not setting a precision, or setting any precision other than 0 works. I think I remember reading something about 0 being the libsass default. But I can't support that by linking to code. Judging from sass_context.cpp and inspect.cpp I'd assume the default is 5.

I'm not sure if this is an issue with code, the documentation, or me being daft (again).

@mgreter
Copy link
Contributor

mgreter commented Apr 27, 2015

Valid, see the same with perl-libsass:

# psass --precision 0 test.scss
div {
  line-height: 2px; }
# psass -v
psass 0.4.0 (perl sass/scss compiler)
  libsass: 3.2.0
  sass2scss: 1.0.3

IMO it should be quite trivial to fix this "edge" case!
Got any expected behavior for negative precision 😄 ?

@xzyfer
Copy link
Contributor

xzyfer commented Apr 30, 2015

Fixed in 3.2.1

@rodneyrehm
Copy link
Contributor Author

Your fix may have gone a tiny bit too far. In 3.2.1 for precision: 0, the following code

$foo: 123px; .m { width: $foo; }

compiles to

.m {
  width: 123.0px; }

I don't think adding .0 is a good idea.

@xzyfer
Copy link
Contributor

xzyfer commented Apr 30, 2015

Are right, yes that's a bug, but it doesn't change the semantic of the code which certainly an improvement.

@xzyfer xzyfer reopened this Apr 30, 2015
@xzyfer xzyfer modified the milestones: 3.2.2, 3.2.1 Apr 30, 2015
@rodneyrehm
Copy link
Contributor Author

Oh, it even got worse:

$foo: 123.4px; .m { width: $foo; }

compiles to

.m {
  width: 123.0px; }

so now we're actually losing precision

@xzyfer
Copy link
Contributor

xzyfer commented Apr 30, 2015

@rodneyrehm I can't reproduce this with give code. Are you sure you're on 3.2.1?

$ sassc --precision=0 test.scss
.m {
  width: 123.0px; }
$ sass --precision=0 test.scss
.m {
  width: 123.0px; }
$ sassc --precision=5 test.scss
.m {
  width: 123.4px; }
$ sass --precision=5 test.scss
.m {
  width: 123.4px; }

@xzyfer
Copy link
Contributor

xzyfer commented Apr 30, 2015

I don't think adding .0 is a good idea.

Yes and no. Ruby Sass adds the .0 if there would have otherwise been a decimal.

The bug here is that we're adding to all numbers regardless.

@rodneyrehm
Copy link
Contributor Author

I see your sassc vs sass test and realize that precision:0 is intended to lose the decimal, it is not the value to set for "use libsass default"? If that's the case, what is the default value?

@xzyfer
Copy link
Contributor

xzyfer commented Apr 30, 2015

precision sets the maximum precision (number of digits after a decimal) to truncate to i.e. 0.5 will not become 0.5000 when precision is 5.

If this what you desire there is no config or flag to achieve this.

@rodneyrehm
Copy link
Contributor Author

No, it's not what I desire. What I want is the ability to tell libsass to use its default value for precision. I assumed 0 would trigger that. Or maybe -1 does. Or maybe nothing triggers the default value, in which case I'd like to know the default value, so I can set it instead of passing in 0. If none of that is possible, I'll go and adjust my code to simply not set precision, in order to have libsass use its default value.

Maybe all of this is really just based on me not understanding that precision:0 is meant to truncate the decimal part.

@mgreter
Copy link
Contributor

mgreter commented Apr 30, 2015

The default value is 5 (was changed some time ago from 3) and no, you cannot tell libsass to use the default again, since it is really only set when the context gets initialized (so you cannot "unset" a config option currently, once it is set), If we would add such a functionality I rather would add specific sass_option_[unset/reset]_presicion or sass_option_get_default_precision. The later would make it possible for host languages to query the default value (which is null for most options).

@xzyfer
Copy link
Contributor

xzyfer commented Apr 30, 2015

As @mgreter said the default is 5 the same as Ruby Sass. We copy Ruby Sass where possible.

There is talk of this changing in the future though - sass/sass#1122

@rodneyrehm
Copy link
Contributor Author

ok, preventing to set the precision seems like the easiest (and apparently future-proof) way. thanks!

@xzyfer
Copy link
Contributor

xzyfer commented Apr 30, 2015

No problem. Apologies for the confusion. We're tracking the extra .0 regression in #1153

@xzyfer xzyfer closed this as completed Apr 30, 2015
@xzyfer xzyfer modified the milestones: 3.2.1, 3.2.2 Apr 30, 2015
@xzyfer xzyfer self-assigned this Apr 30, 2015
@rodneyrehm
Copy link
Contributor Author

No need to apologize, obviously I wasn't able to make clear what I wanted…
Thanks guys! :)

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