Skip to content

Commit

Permalink
Merge branch 'better_numeric_compression' into stable
Browse files Browse the repository at this point in the history
Conflicts:
	doc-src/SASS_CHANGELOG.md
  • Loading branch information
chriseppstein committed Nov 21, 2015
2 parents b58d5a1 + 85b3662 commit c29da63
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc-src/SASS_CHANGELOG.md
Expand Up @@ -21,6 +21,9 @@
* Mitigate a race condition when multiple threads are using the same
`Sass::Plugin` object at once.

* In compressed mode, numbers between -1 and 1 now have the
leading 0 omitted.

## 3.4.19 (09 October 2015)

* Sass numeric equality now better handles float-point errors. Any
Expand Down
1 change: 1 addition & 0 deletions lib/sass/script/parser.rb
Expand Up @@ -538,6 +538,7 @@ def number
tok = try_tok(:number)
return selector unless tok
num = tok.value
num.options = @options
num.original = num.to_s
literal_node(num, tok.source_range.start_pos)
end
Expand Down
3 changes: 3 additions & 0 deletions lib/sass/script/value/number.rb
Expand Up @@ -289,6 +289,9 @@ def inspect(opts = {})
# and confusing.
str = ("%0.#{self.class.precision}f" % value).gsub(/0*$/, '') if str.include?('e')

if @options && options[:style] == :compressed
str.sub!(/^(-)?0\./, '\1.')
end
unitless? ? str : "#{str}#{unit_str}"
end
alias_method :to_sass, :inspect
Expand Down
9 changes: 9 additions & 0 deletions test/sass/script_test.rb
Expand Up @@ -1177,12 +1177,21 @@ def test_equality_uses_an_epsilon
assert_equal "true", resolve("29 == (29 / 7 * 7)")
end

def test_compressed_output_of_numbers_with_leading_zeros
assert_equal "1.5", resolve("1.5", :style => :compressed)
assert_equal ".5", resolve("0.5", :style => :compressed)
assert_equal "-.5", resolve("-0.5", :style => :compressed)
assert_equal "0.5", resolve("0.5", :style => :compact)
end


private

def resolve(str, opts = {}, environment = env)
munge_filename opts
val = eval(str, opts, environment)
assert_kind_of Sass::Script::Value::Base, val
val.options = opts
val.is_a?(Sass::Script::Value::String) ? val.value : val.to_s
end

Expand Down

0 comments on commit c29da63

Please sign in to comment.