Fixes #940 - handles more `font` keywords.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Tue, 9 May 2017 18:21:31 +0000 (20:21 +0200)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 10 May 2017 17:42:13 +0000 (19:42 +0200)
Why:

* The list wasn't exhaustive, hopefully the new one is.

History.md
lib/optimizer/level-2/break-up.js
lib/optimizer/validator.js
test/optimizer/level-2/break-up-test.js

index 8af325b..033014a 100644 (file)
@@ -1,3 +1,8 @@
+[4.1.2 / 2017-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v4.1.1...4.1)
+==================
+
+* Fixed issue [#940](https://github.com/jakubpawlowicz/clean-css/issues/940) - handling more `font` keywords.
+
 [4.1.1 / 2017-05-08](https://github.com/jakubpawlowicz/clean-css/compare/v4.1.0...v4.1.1)
 ==================
 
index 45d5c31..b6c9610 100644 (file)
@@ -288,13 +288,13 @@ function font(property, compactable, validator) {
     throw new InvalidPropertyError('Missing font values at ' + formatPosition(property.all[property.position][1][2][0]) + '. Ignoring.');
   }
 
-  if (values.length == 1 && (validator.isFontKeyword(values[0][1]) || validator.isPrefixed(values[0][1]))) {
-    values[0][1] = Marker.INTERNAL + values[0][1];
+  if (values.length == 1 && values[0][1] == 'inherit') {
     style.value = variant.value = weight.value = stretch.value = size.value = height.value = family.value = values;
     return components;
   }
 
-  if (values.length == 1 && values[0][1] == 'inherit') {
+  if (values.length == 1 && (validator.isFontKeyword(values[0][1]) || validator.isGlobal(values[0][1]) || validator.isPrefixed(values[0][1]))) {
+    values[0][1] = Marker.INTERNAL + values[0][1];
     style.value = variant.value = weight.value = stretch.value = size.value = height.value = family.value = values;
     return components;
   }
index 820f840..cfccd0f 100644 (file)
@@ -180,7 +180,8 @@ var Keywords = {
     'menu',
     'message-box',
     'small-caption',
-    'status-bar'
+    'status-bar',
+    'unset'
   ],
   'font-size': [
     'large',
index 842dc8f..514f25b 100644 (file)
@@ -1475,6 +1475,48 @@ vows.describe(breakUp)
           assert.deepEqual(components[6].value, [['property-value', '-clean-css-icon']]);
         }
       },
+      'unset font': {
+        'topic': function () {
+          return _breakUp([
+            [
+              'property',
+              ['property-name', 'font'],
+              ['property-value', 'unset']
+            ]
+          ]);
+        },
+        'has 7 components': function (components) {
+          assert.lengthOf(components, 7);
+        },
+        'has font-style': function (components) {
+          assert.equal(components[0].name, 'font-style');
+          assert.deepEqual(components[0].value, [['property-value', '-clean-css-unset']]);
+        },
+        'has font-variant': function (components) {
+          assert.equal(components[1].name, 'font-variant');
+          assert.deepEqual(components[1].value, [['property-value', '-clean-css-unset']]);
+        },
+        'has font-weight': function (components) {
+          assert.equal(components[2].name, 'font-weight');
+          assert.deepEqual(components[2].value, [['property-value', '-clean-css-unset']]);
+        },
+        'has font-stretch': function (components) {
+          assert.equal(components[3].name, 'font-stretch');
+          assert.deepEqual(components[3].value, [['property-value', '-clean-css-unset']]);
+        },
+        'has font-size': function (components) {
+          assert.equal(components[4].name, 'font-size');
+          assert.deepEqual(components[4].value, [['property-value', '-clean-css-unset']]);
+        },
+        'has line-height': function (components) {
+          assert.equal(components[5].name, 'line-height');
+          assert.deepEqual(components[5].value, [['property-value', '-clean-css-unset']]);
+        },
+        'has font-family': function (components) {
+          assert.equal(components[6].name, 'font-family');
+          assert.deepEqual(components[6].value, [['property-value', '-clean-css-unset']]);
+        }
+      },
       'system font with vendor prefix': {
         'topic': function () {
           return _breakUp([