Skip to content

Commit

Permalink
issue #80: recognize vendor properties
Browse files Browse the repository at this point in the history
  • Loading branch information
afelix committed Sep 17, 2012
1 parent d7c6412 commit 9ec9566
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 27 deletions.
47 changes: 38 additions & 9 deletions lib/compressor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1077,9 +1077,11 @@ CSSOCompressor.prototype.buildPPre = function(pre, p, v, d, freeze) {
0, // hsl
0, // hsla
0 // rgba
];
],
vID = '';

for (var i = 0; i < _v.length; i++) {
if (!vID) vID = this.getVendorIDFromToken(_v[i]);
switch(_v[i][1]) {
case 'vhash':
case 'ident':
Expand All @@ -1099,7 +1101,38 @@ CSSOCompressor.prototype.buildPPre = function(pre, p, v, d, freeze) {
}
}

return fp + pre + p + colorMark.join('');
return fp + pre + p + colorMark.join('') + (vID ? vID : '');
};

CSSOCompressor.prototype.vendorID = {
'-o-': 'o',
'-moz-': 'm',
'-webkit-': 'w',
'-ms-': 'i',
'-epub-': 'e',
'-apple-': 'a',
'-xv-': 'x',
'-wap-': 'p'
};

CSSOCompressor.prototype.getVendorIDFromToken = function(token) {
var vID;
switch(token[1]) {
case 'ident':
if (vID = this.getVendorFromString(token[2])) return this.vendorID[vID];
break;
case 'funktion':
if (vID = this.getVendorFromString(token[2][2])) return this.vendorID[vID];
break;
}
};

CSSOCompressor.prototype.getVendorFromString = function(string) {
var vendor = string.charAt(0), i;
if (vendor === '-') {
if ((i = string.indexOf('-', 2)) !== -1) return string.substr(0, i + 1);
}
return '';
};

CSSOCompressor.prototype.deleteProperty = function(block, id) {
Expand Down Expand Up @@ -1159,17 +1192,13 @@ CSSOCompressor.prototype.needless = function(name, props, pre, imp, v, d, freeze
name = name.substr(2);
} else hack = '';

var vendor = name.charAt(0), i;
if (vendor === '-') {
if ((i = name.indexOf('-', 2)) !== -1) vendor = name.substr(0, i + 1);
} else vendor = '';

var prop = name.substr(vendor.length),
var vendor = this.getVendorFromString(name),
prop = name.substr(vendor.length),
x, t, ppre;

if (prop in this.nlTable) {
x = this.nlTable[prop];
for (i = 0; i < x.length; i++) {
for (var i = 0; i < x.length; i++) {
ppre = this.buildPPre(pre, hack + vendor + x[i], v, d, freeze);
if (t = props[ppre]) return (!imp || t.imp);
}
Expand Down
47 changes: 38 additions & 9 deletions src/compressor.shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -912,9 +912,11 @@ CSSOCompressor.prototype.buildPPre = function(pre, p, v, d, freeze) {
0, // hsl
0, // hsla
0 // rgba
];
],
vID = '';

for (var i = 0; i < _v.length; i++) {
if (!vID) vID = this.getVendorIDFromToken(_v[i]);
switch(_v[i][1]) {
case 'vhash':
case 'ident':
Expand All @@ -934,7 +936,38 @@ CSSOCompressor.prototype.buildPPre = function(pre, p, v, d, freeze) {
}
}

return fp + pre + p + colorMark.join('');
return fp + pre + p + colorMark.join('') + (vID ? vID : '');
};

CSSOCompressor.prototype.vendorID = {
'-o-': 'o',
'-moz-': 'm',
'-webkit-': 'w',
'-ms-': 'i',
'-epub-': 'e',
'-apple-': 'a',
'-xv-': 'x',
'-wap-': 'p'
};

CSSOCompressor.prototype.getVendorIDFromToken = function(token) {
var vID;
switch(token[1]) {
case 'ident':
if (vID = this.getVendorFromString(token[2])) return this.vendorID[vID];
break;
case 'funktion':
if (vID = this.getVendorFromString(token[2][2])) return this.vendorID[vID];
break;
}
};

CSSOCompressor.prototype.getVendorFromString = function(string) {
var vendor = string.charAt(0), i;
if (vendor === '-') {
if ((i = string.indexOf('-', 2)) !== -1) return string.substr(0, i + 1);
}
return '';
};

CSSOCompressor.prototype.deleteProperty = function(block, id) {
Expand Down Expand Up @@ -994,17 +1027,13 @@ CSSOCompressor.prototype.needless = function(name, props, pre, imp, v, d, freeze
name = name.substr(2);
} else hack = '';

var vendor = name.charAt(0), i;
if (vendor === '-') {
if ((i = name.indexOf('-', 2)) !== -1) vendor = name.substr(0, i + 1);
} else vendor = '';

var prop = name.substr(vendor.length),
var vendor = this.getVendorFromString(name),
prop = name.substr(vendor.length),
x, t, ppre;

if (prop in this.nlTable) {
x = this.nlTable[prop];
for (i = 0; i < x.length; i++) {
for (var i = 0; i < x.length; i++) {
ppre = this.buildPPre(pre, hack + vendor + x[i], v, d, freeze);
if (t = props[ppre]) return (!imp || t.imp);
}
Expand Down
1 change: 1 addition & 0 deletions test/data/test_stylesheet/issue80.test1.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
div{height:-webkit-calc(100% - 30px);height:-moz-calc(100% - 30px);height:-ms-calc(100% - 30px);height:-o-calc(100% - 30px);height:calc(100% - 30px)}
7 changes: 7 additions & 0 deletions test/data/test_stylesheet/issue80.test1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
div {
height: -webkit-calc(100% - 30px);
height: -moz-calc(100% - 30px);
height: -ms-calc(100% - 30px);
height: -o-calc(100% - 30px);
height: calc(100% - 30px);
}
47 changes: 38 additions & 9 deletions web/csso.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -2010,9 +2010,11 @@ CSSOCompressor.prototype.buildPPre = function(pre, p, v, d, freeze) {
0, // hsl
0, // hsla
0 // rgba
];
],
vID = '';

for (var i = 0; i < _v.length; i++) {
if (!vID) vID = this.getVendorIDFromToken(_v[i]);
switch(_v[i][1]) {
case 'vhash':
case 'ident':
Expand All @@ -2032,7 +2034,38 @@ CSSOCompressor.prototype.buildPPre = function(pre, p, v, d, freeze) {
}
}

return fp + pre + p + colorMark.join('');
return fp + pre + p + colorMark.join('') + (vID ? vID : '');
};

CSSOCompressor.prototype.vendorID = {
'-o-': 'o',
'-moz-': 'm',
'-webkit-': 'w',
'-ms-': 'i',
'-epub-': 'e',
'-apple-': 'a',
'-xv-': 'x',
'-wap-': 'p'
};

CSSOCompressor.prototype.getVendorIDFromToken = function(token) {
var vID;
switch(token[1]) {
case 'ident':
if (vID = this.getVendorFromString(token[2])) return this.vendorID[vID];
break;
case 'funktion':
if (vID = this.getVendorFromString(token[2][2])) return this.vendorID[vID];
break;
}
};

CSSOCompressor.prototype.getVendorFromString = function(string) {
var vendor = string.charAt(0), i;
if (vendor === '-') {
if ((i = string.indexOf('-', 2)) !== -1) return string.substr(0, i + 1);
}
return '';
};

CSSOCompressor.prototype.deleteProperty = function(block, id) {
Expand Down Expand Up @@ -2092,17 +2125,13 @@ CSSOCompressor.prototype.needless = function(name, props, pre, imp, v, d, freeze
name = name.substr(2);
} else hack = '';

var vendor = name.charAt(0), i;
if (vendor === '-') {
if ((i = name.indexOf('-', 2)) !== -1) vendor = name.substr(0, i + 1);
} else vendor = '';

var prop = name.substr(vendor.length),
var vendor = this.getVendorFromString(name),
prop = name.substr(vendor.length),
x, t, ppre;

if (prop in this.nlTable) {
x = this.nlTable[prop];
for (i = 0; i < x.length; i++) {
for (var i = 0; i < x.length; i++) {
ppre = this.buildPPre(pre, hack + vendor + x[i], v, d, freeze);
if (t = props[ppre]) return (!imp || t.imp);
}
Expand Down

0 comments on commit 9ec9566

Please sign in to comment.