From 429f47297073079f7550a728d9790d00c0ab05eb Mon Sep 17 00:00:00 2001 From: Oskari Groenroos Date: Mon, 15 Feb 2021 14:35:23 +0000 Subject: [PATCH 1/3] Add deg and fr as exceptions for 0 value unit omission --- lib/visitor/compiler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/visitor/compiler.js b/lib/visitor/compiler.js index bed07ce87..3aea52f03 100644 --- a/lib/visitor/compiler.js +++ b/lib/visitor/compiler.js @@ -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 ('%' != type && 's' != type && 'ms' != type && 'deg' != type && 'fr' != type && 0 == n) return '0'; // Omit leading '0' on floats if (float && n < 1 && n > -1) { return n.toString().replace('0.', '.') + type; From 806eaf42e2345632458af010ea79839ed5fc271a Mon Sep 17 00:00:00 2001 From: groenroos Date: Sun, 22 Aug 2021 16:45:21 +0100 Subject: [PATCH 2/3] Make if statement more concise --- lib/visitor/compiler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/visitor/compiler.js b/lib/visitor/compiler.js index 3aea52f03..9a793339e 100644 --- a/lib/visitor/compiler.js +++ b/lib/visitor/compiler.js @@ -414,7 +414,7 @@ Compiler.prototype.visitUnit = function(unit){ // Compress if (this.compress) { // Always return '0' unless the unit is a percentage, time, degree or fraction - if ('%' != type && 's' != type && 'ms' != type && 'deg' != type && 'fr' != type && 0 == n) return '0'; + 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; From c7279a2671e9755b40166b33172290d6a828c1a7 Mon Sep 17 00:00:00 2001 From: groenroos Date: Sun, 22 Aug 2021 16:45:37 +0100 Subject: [PATCH 3/3] Add unit tests for deg and fr --- test/cases/compress.units.css | 2 +- test/cases/compress.units.styl | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/test/cases/compress.units.css b/test/cases/compress.units.css index 6dc1c6247..3e67b61ad 100644 --- a/test/cases/compress.units.css +++ b/test/cases/compress.units.css @@ -1 +1 @@ -body{foo:0;foo:0;foo:15;foo:-15;foo:15px;foo:-15px}body{foo:.1;foo:-.1;foo:1.1;foo:-1.1;foo:.1;foo:-.1;foo:10.1;foo:-10.1}body{foo:0s;foo:0ms} \ No newline at end of file +body{foo:0;foo:0;foo:15;foo:-15;foo:15px;foo:-15px}body{foo:.1;foo:-.1;foo:1.1;foo:-1.1;foo:.1;foo:-.1;foo:10.1;foo:-10.1}body{foo:0s;foo:0ms}body{foo:0deg;foo:15deg;foo:-15deg}body{foo:0fr;foo:15fr;foo:-15fr} \ No newline at end of file diff --git a/test/cases/compress.units.styl b/test/cases/compress.units.styl index e24da513a..b1c66a288 100644 --- a/test/cases/compress.units.styl +++ b/test/cases/compress.units.styl @@ -19,3 +19,13 @@ body body foo 0s foo 0ms + +body + foo 0deg + foo 15deg + foo -15deg + +body + foo 0fr + foo 15fr + foo -15fr