From 5e91afd947b3d42bb583f61589756d8de15316f0 Mon Sep 17 00:00:00 2001 From: Roman Dvornov Date: Fri, 6 Jan 2017 15:51:09 +0500 Subject: [PATCH] add support for \0 IE hack (fixes #320) --- .../restructure/4-restructShorthand.js | 9 +++--- lib/compressor/restructure/6-restructBlock.js | 8 ++--- test/fixture/compress/hack0.css | 30 +++++++++++++++++++ test/fixture/compress/hack0.min.css | 1 + test/fixture/compress/hack9.css | 2 +- 5 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 test/fixture/compress/hack0.css create mode 100644 test/fixture/compress/hack0.min.css diff --git a/lib/compressor/restructure/4-restructShorthand.js b/lib/compressor/restructure/4-restructShorthand.js index 4edae286..aa95e3cc 100644 --- a/lib/compressor/restructure/4-restructShorthand.js +++ b/lib/compressor/restructure/4-restructShorthand.js @@ -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': @@ -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; } @@ -301,7 +302,7 @@ TRBL.prototype.getValue = function() { result.push({ type: 'Space' }, { type: 'Identifier', info: {}, - name: '\\9' + name: this.iehack }); } diff --git a/lib/compressor/restructure/6-restructBlock.js b/lib/compressor/restructure/6-restructBlock.js index 7b3fd830..4933eed4 100644 --- a/lib/compressor/restructure/6-restructBlock.js +++ b/lib/compressor/restructure/6-restructBlock.js @@ -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) { @@ -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') { @@ -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; } diff --git a/test/fixture/compress/hack0.css b/test/fixture/compress/hack0.css new file mode 100644 index 00000000..4c9da897 --- /dev/null +++ b/test/fixture/compress/hack0.css @@ -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; +} diff --git a/test/fixture/compress/hack0.min.css b/test/fixture/compress/hack0.min.css new file mode 100644 index 00000000..b12ab20e --- /dev/null +++ b/test/fixture/compress/hack0.min.css @@ -0,0 +1 @@ +.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}.selector{width:6ch;width:7ch\0} diff --git a/test/fixture/compress/hack9.css b/test/fixture/compress/hack9.css index 927b2525..f5c81824 100644 --- a/test/fixture/compress/hack9.css +++ b/test/fixture/compress/hack9.css @@ -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 {