diff --git a/lib/compressor/restructure/restructBlock.js b/lib/compressor/restructure/restructBlock.js index e09249e3..8fb1dd77 100644 --- a/lib/compressor/restructure/restructBlock.js +++ b/lib/compressor/restructure/restructBlock.js @@ -5,6 +5,10 @@ var dontRestructure = { 'src': 1 // https://github.com/afelix/csso/issues/50 }; +// https://developer.mozilla.org/en-US/docs/Web/CSS/display#Browser_compatibility +var IS_DISPLAY = /display$/; +var DISPLAY_DONT_MIX_VALUE = /table|ruby|flex|-(flex)?box$|grid|contents|run-in/; + var NEEDLESS_TABLE = { 'border-width': ['border'], 'border-style': ['border'], @@ -108,7 +112,7 @@ function getPropertyFingerprint(property, value, declaration, freeze) { var vendorId = ''; var hack9 = 0; var functions = {}; - var units = {}; + var special = {}; for (var i = 0; i < value.length; i++) { if (!vendorId) { @@ -117,9 +121,16 @@ function getPropertyFingerprint(property, value, declaration, freeze) { switch (value[i].type) { case 'Identifier': - if (value[i].name === '\\9') { + var name = value[i].name; + + if (name === '\\9') { hack9 = 1; } + + if (IS_DISPLAY.test(property) && DISPLAY_DONT_MIX_VALUE.test(name)) { + special[name] = true; + } + break; case 'Function': @@ -140,6 +151,7 @@ function getPropertyFingerprint(property, value, declaration, freeze) { case 'Dimension': var unit = value[i].unit; + switch (unit) { // is not supported until IE11 case 'rem': @@ -151,7 +163,7 @@ function getPropertyFingerprint(property, value, declaration, freeze) { case 'vmin': case 'vmax': case 'vm': // IE9 supporting "vm" instead of "vmin". - units[unit] = true; + special[unit] = true; break; } break; @@ -161,7 +173,7 @@ function getPropertyFingerprint(property, value, declaration, freeze) { return ( fp + property + '[' + Object.keys(functions) + ']' + - Object.keys(units) + + Object.keys(special) + hack9 + vendorId ); } diff --git a/test/fixture/compress/display.css b/test/fixture/compress/display.css new file mode 100644 index 00000000..7889d536 --- /dev/null +++ b/test/fixture/compress/display.css @@ -0,0 +1,16 @@ +/* + issue #259 don't override values with different browser support +*/ + +.test { + display: inline-block; + display: -webkit-box; + display: -moz-box; + display: -webkit-flex; + display: -moz-flex; + display: -ms-flexbox; + display: inline-block; + display: table-cell; + display: grid; + display: flex; +} diff --git a/test/fixture/compress/display.min.css b/test/fixture/compress/display.min.css new file mode 100644 index 00000000..ee734aa4 --- /dev/null +++ b/test/fixture/compress/display.min.css @@ -0,0 +1 @@ +.test{display:-webkit-box;display:-moz-box;display:-webkit-flex;display:-moz-flex;display:-ms-flexbox;display:inline-block;display:table-cell;display:grid;display:flex}