Skip to content

Commit

Permalink
Add deg and fr as exceptions for 0 value unit omission (#2578)
Browse files Browse the repository at this point in the history
* Add deg and fr as exceptions for 0 value unit omission

* Make if statement more concise

* Add unit tests for deg and fr
  • Loading branch information
groenroos committed Sep 1, 2021
1 parent 57480a4 commit 7334567
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/visitor/compiler.js
Expand Up @@ -413,8 +413,8 @@ Compiler.prototype.visitUnit = function(unit){

// Compress
if (this.compress) {
// Always return '0' unless the unit is a percentage or time
if ('%' != type && 's' != type && 'ms' != type && 0 == n) return '0';
// Always return '0' unless the unit is a percentage, time, degree or fraction
if (!(['%', 's', 'ms', 'deg', 'fr'].includes(type)) && 0 == n) return '0';
// Omit leading '0' on floats
if (float && n < 1 && n > -1) {
return n.toString().replace('0.', '.') + type;
Expand Down
2 changes: 1 addition & 1 deletion test/cases/compress.units.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions test/cases/compress.units.styl
Expand Up @@ -19,3 +19,13 @@ body
body
foo 0s
foo 0ms

body
foo 0deg
foo 15deg
foo -15deg

body
foo 0fr
foo 15fr
foo -15fr

0 comments on commit 7334567

Please sign in to comment.