Fixes #620 - `bold` style in font shorthands.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Tue, 14 Jul 2015 07:51:36 +0000 (08:51 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Tue, 14 Jul 2015 09:33:42 +0000 (10:33 +0100)
Looking forward to an ultimate fix with #254.

History.md
lib/selectors/simple.js
test/selectors/simple-test.js

index 61ef29a..0495f96 100644 (file)
@@ -3,6 +3,11 @@
 
 * Fixed issue [#599](https://github.com/jakubpawlowicz/clean-css/issues/599) - support for inlined source maps.
 
+[3.3.6 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.3.5...3.3)
+==================
+
+* Fixed issue [#620](https://github.com/jakubpawlowicz/clean-css/issues/620) - `bold` style in font shorthands.
+
 [3.3.5 / 2015-07-01](https://github.com/jakubpawlowicz/clean-css/compare/v3.3.4...v3.3.5)
 ==================
 
index 6dcff70..71e42cd 100644 (file)
@@ -13,6 +13,7 @@ var CHARSET_REGEXP = new RegExp('^' + CHARSET_TOKEN, 'i');
 
 var FONT_NUMERAL_WEIGHTS = ['100', '200', '300', '400', '500', '600', '700', '800', '900'];
 var FONT_NAME_WEIGHTS = ['normal', 'bold', 'bolder', 'lighter'];
+var FONT_NAME_WEIGHTS_WITHOUT_NORMAL = ['bold', 'bolder', 'lighter'];
 
 var valueMinifiers = {
   'background': function (value, index, total) {
@@ -200,7 +201,13 @@ function minifyFont(property) {
     return;
 
   var toOptimize;
-  if (FONT_NAME_WEIGHTS.indexOf(property[1][0]) > -1)
+  if (FONT_NAME_WEIGHTS_WITHOUT_NORMAL.indexOf(property[1][0]) > -1)
+    toOptimize = 1;
+  else if (property[2] && FONT_NAME_WEIGHTS_WITHOUT_NORMAL.indexOf(property[2][0]) > -1)
+    toOptimize = 2;
+  else if (property[3] && FONT_NAME_WEIGHTS_WITHOUT_NORMAL.indexOf(property[3][0]) > -1)
+    toOptimize = 3;
+  else if (FONT_NAME_WEIGHTS.indexOf(property[1][0]) > -1)
     toOptimize = 1;
   else if (property[2] && FONT_NAME_WEIGHTS.indexOf(property[2][0]) > -1)
     toOptimize = 2;
index a601d71..10cbb2b 100644 (file)
@@ -321,6 +321,18 @@ vows.describe('simple optimizations')
       'with line height': [
         'a{font: 11px/normal sans-serif}',
         [['font', '11px', '/', 'normal', 'sans-serif']]
+      ],
+      'with mixed bold weight and variant #1': [
+        'a{font:normal bold 16px sans-serif}',
+        [['font', 'normal', '700', '16px', 'sans-serif']]
+      ],
+      'with mixed bold weight and variant #2': [
+        'a{font:bold normal 16px sans-serif}',
+        [['font', '700', 'normal', '16px', 'sans-serif']]
+      ],
+      'with mixed bold weight and variant #3': [
+        'a{font:bold normal normal 16px sans-serif}',
+        [['font', 'bold', 'normal', 'normal', '16px', 'sans-serif']] // pending #254
       ]
     })
   )