Skip to content

Commit

Permalink
don't override display values with different browser support (fixes #259
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lahmatiy committed Jan 24, 2016
1 parent 65a9f76 commit 9ef8a08
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/compressor/restructure/restructBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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) {
Expand All @@ -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':
Expand All @@ -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':
Expand All @@ -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;
Expand All @@ -161,7 +173,7 @@ function getPropertyFingerprint(property, value, declaration, freeze) {
return (
fp + property +
'[' + Object.keys(functions) + ']' +
Object.keys(units) +
Object.keys(special) +
hack9 + vendorId
);
}
Expand Down
16 changes: 16 additions & 0 deletions test/fixture/compress/display.css
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions test/fixture/compress/display.min.css
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit 9ef8a08

Please sign in to comment.