Skip to content

Commit

Permalink
add support for \0 IE hack (fixes #320)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Jan 6, 2017
1 parent 9892726 commit 5e91afd
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
9 changes: 5 additions & 4 deletions lib/compressor/restructure/4-restructShorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,16 @@ function TRBL(name) {

TRBL.prototype.getValueSequence = function(value, count) {
var values = [];
var iehack = false;
var iehack = '';
var hasBadValues = value.sequence.some(function(child) {
var special = false;

switch (child.type) {
case 'Identifier':
switch (child.name) {
case '\\0':
case '\\9':
iehack = true;
iehack = child.name;
return;

case 'inherit':
Expand Down Expand Up @@ -141,7 +142,7 @@ TRBL.prototype.getValueSequence = function(value, count) {
return false;
}

if (typeof this.iehack === 'boolean' && this.iehack !== iehack) {
if (typeof this.iehack === 'string' && this.iehack !== iehack) {
return false;
}

Expand Down Expand Up @@ -301,7 +302,7 @@ TRBL.prototype.getValue = function() {
result.push({ type: 'Space' }, {
type: 'Identifier',
info: {},
name: '\\9'
name: this.iehack
});
}

Expand Down
8 changes: 4 additions & 4 deletions lib/compressor/restructure/6-restructBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function getPropertyFingerprint(propertyName, declaration, fingerprints) {

if (!fingerprint) {
var vendorId = '';
var hack9 = '';
var iehack = '';
var special = {};

declaration.value.sequence.each(function walk(node) {
Expand All @@ -90,8 +90,8 @@ function getPropertyFingerprint(propertyName, declaration, fingerprints) {
vendorId = resolveKeyword(name).vendor;
}

if (/\\9/.test(name)) {
hack9 = name;
if (/\\[09]/.test(name)) {
iehack = RegExp.lastMatch;
}

if (realName === 'cursor') {
Expand Down Expand Up @@ -151,7 +151,7 @@ function getPropertyFingerprint(propertyName, declaration, fingerprints) {
}
});

fingerprint = '|' + Object.keys(special).sort() + '|' + hack9 + vendorId;
fingerprint = '|' + Object.keys(special).sort() + '|' + iehack + vendorId;

fingerprints[declarationId] = fingerprint;
}
Expand Down
30 changes: 30 additions & 0 deletions test/fixture/compress/hack0.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Declaration merge should be avoided when value has \0
*/

.a {
border-top: 4px dashed;
border-top: 4px solid \0;
}
.a-2 {
border-top: 5px dashed;
border-top: 5px solid\0;
}
.b {
margin: 5px;
margin: 4px \0;
padding: 5px;
padding: 4px \0;
background: 10px 20px;
background: 20px 30px \0;
}
.c {
margin: 4px 0 0;
margin-top: 1px \0;
}

/* issue #320 */
.selector {
width: 6ch;
width: 7ch\0;
}
1 change: 1 addition & 0 deletions test/fixture/compress/hack0.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/fixture/compress/hack9.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Bootstrap and others uses \9 hack to target IE8-9
When value has \9 it should be avoid of merge
Declaration merge should be avoided when value has \9
*/

.a {
Expand Down

0 comments on commit 5e91afd

Please sign in to comment.