From 0cd525909bb6bd93dd6df4b68f23a5699e4810e3 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Tue, 14 Jul 2015 08:51:36 +0100 Subject: [PATCH] Fixes #620 - `bold` style in font shorthands. Looking forward to an ultimate fix with #254. --- History.md | 5 +++++ lib/selectors/simple.js | 9 ++++++++- test/selectors/simple-test.js | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index 61ef29ab..0495f96f 100644 --- a/History.md +++ b/History.md @@ -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) ================== diff --git a/lib/selectors/simple.js b/lib/selectors/simple.js index 6dcff708..71e42cda 100644 --- a/lib/selectors/simple.js +++ b/lib/selectors/simple.js @@ -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; diff --git a/test/selectors/simple-test.js b/test/selectors/simple-test.js index a601d71a..10cbb2b7 100644 --- a/test/selectors/simple-test.js +++ b/test/selectors/simple-test.js @@ -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 ] }) ) -- 2.34.1