From d3ed28f9006d68c815c378ce77e18adf7d6889e0 Mon Sep 17 00:00:00 2001 From: Denis Payase Date: Thu, 7 Nov 2013 20:22:34 +0400 Subject: [PATCH 1/4] Fix issue #98 --- lib/options/vendor-prefix-align.js | 4 ++-- test/vendor-prefix-align.js | 8 +++++++- test/vendor-prefix-align/both.css | 5 +++++ test/vendor-prefix-align/both.expected.css | 5 +++++ 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 test/vendor-prefix-align/both.css create mode 100644 test/vendor-prefix-align/both.expected.css diff --git a/lib/options/vendor-prefix-align.js b/lib/options/vendor-prefix-align.js index eb087b82..b31beb45 100644 --- a/lib/options/vendor-prefix-align.js +++ b/lib/options/vendor-prefix-align.js @@ -73,8 +73,8 @@ module.exports = { */ _valName: function(item) { return item[0] === 'declaration' && item[2] && item[2][2] && - item[2][2][0] === 'funktion' && item[2][2][1][0] === 'ident' && - item[2][2][1][1]; + ((item[2][2][0] === 'funktion' && item[2][2][1][0] === 'ident' && item[2][2][1][1]) || + (item[2][2][0] === 'ident' && item[2][2][1])); }, /** diff --git a/test/vendor-prefix-align.js b/test/vendor-prefix-align.js index d5cf97b9..d58be6df 100644 --- a/test/vendor-prefix-align.js +++ b/test/vendor-prefix-align.js @@ -35,11 +35,17 @@ describe('options/vendor-prefix-align', function() { assert.equal(comb.processString(input), expected); }); + it('Should correct align prefixes in preoperties and values at the same time', function() { + var input = fs.readFileSync('./test/vendor-prefix-align/both.css', 'utf8'); + var expected = fs.readFileSync('./test/vendor-prefix-align/both.expected.css', 'utf8'); + + assert.equal(comb.processString(input), expected); + }); + it('Should always correctly align prefixes', function() { var input = fs.readFileSync('./test/vendor-prefix-align/complex.css', 'utf8'); var expected = fs.readFileSync('./test/vendor-prefix-align/complex.expected.css', 'utf8'); assert.equal(comb.processString(input), expected); }); - }); diff --git a/test/vendor-prefix-align/both.css b/test/vendor-prefix-align/both.css new file mode 100644 index 00000000..3791d296 --- /dev/null +++ b/test/vendor-prefix-align/both.css @@ -0,0 +1,5 @@ +.serp-block__head_animation_yes +{ + -webkit-transition: -webkit-transform 150ms linear; + transition: transform 150ms linear; +} diff --git a/test/vendor-prefix-align/both.expected.css b/test/vendor-prefix-align/both.expected.css new file mode 100644 index 00000000..f58aa02a --- /dev/null +++ b/test/vendor-prefix-align/both.expected.css @@ -0,0 +1,5 @@ +.serp-block__head_animation_yes +{ + -webkit-transition: -webkit-transform 150ms linear; + transition: transform 150ms linear; +} From 6575105d36fa5f06a0b529d98db0e6885adaa05a Mon Sep 17 00:00:00 2001 From: Denis Payase Date: Mon, 11 Nov 2013 21:33:43 +0400 Subject: [PATCH 2/4] Update getter functions --- lib/options/vendor-prefix-align.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/options/vendor-prefix-align.js b/lib/options/vendor-prefix-align.js index b31beb45..bd6c1c16 100644 --- a/lib/options/vendor-prefix-align.js +++ b/lib/options/vendor-prefix-align.js @@ -60,8 +60,9 @@ module.exports = { * @param {node} item * @returns {String|false|undefined} */ - _declName: function(item) { - return item[0] === 'declaration' && item[1][1][1]; + _getDeclName: function(node) { + if (node[0] !== 'declaration') return; + return node[1][1][1]; }, /** @@ -71,10 +72,13 @@ module.exports = { * @param {node} item * @returns {String|false|undefined} */ - _valName: function(item) { - return item[0] === 'declaration' && item[2] && item[2][2] && - ((item[2][2][0] === 'funktion' && item[2][2][1][0] === 'ident' && item[2][2][1][1]) || - (item[2][2][0] === 'ident' && item[2][2][1])); + _getValName: function(node) { + if (node[0] !== 'declaration' || !node[2] || !node[2][2]) + return; + if (node[2][2][0] === 'ident') + return node[2][2][1]; + if (node[2][2][0] === 'funktion') + return node[2][2][1][1]; }, /** @@ -140,18 +144,18 @@ module.exports = { var _this = this; // Gathering Info - this._walk(node, this._declName, function(info, i) { + this._walk(node, this._getDeclName, function(info, i) { _this._updateDict(info, dict, node[i - 1][1]); }); - this._walk(node, this._valName, function(info, i) { + this._walk(node, this._getValName, function(info, i) { _this._updateDict(info, dict, node[i][2][1][1]); }); // Update nodes - this._walk(node, this._declName, function(info, i) { + this._walk(node, this._getDeclName, function(info, i) { node[i - 1][1] = _this._updateIndent(info, dict, node[i - 1][1]); }); - this._walk(node, this._valName, function(info, i) { + this._walk(node, this._getValName, function(info, i) { node[i][2][1][1] = _this._updateIndent(info, dict, node[i][2][1][1]); }); } From 8abf1950233d090e12abe6f942cdcdbfb623beb8 Mon Sep 17 00:00:00 2001 From: Denis Payase Date: Mon, 11 Nov 2013 21:35:51 +0400 Subject: [PATCH 3/4] Added examples in JSDocs --- lib/options/vendor-prefix-align.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/options/vendor-prefix-align.js b/lib/options/vendor-prefix-align.js index bd6c1c16..3ed8a920 100644 --- a/lib/options/vendor-prefix-align.js +++ b/lib/options/vendor-prefix-align.js @@ -56,9 +56,12 @@ module.exports = { /** * Internal * - * Selector for property name. - * @param {node} item - * @returns {String|false|undefined} + * Return property name. + * e.g. + * for:'color: #fff' + * returns string: 'color' + * @param {node} node + * @returns {String|undefined} */ _getDeclName: function(node) { if (node[0] !== 'declaration') return; @@ -68,9 +71,14 @@ module.exports = { /** * Internal * - * Selector for value name. - * @param {node} item - * @returns {String|false|undefined} + * Return for value name. + * e.g. + * for: '-webkit-transition: -webkit-transform 150ms linear' + * returns string: '-webkit-transform', and + * for: 'background: -webkit-linear-gradient(...)' + * returns string: '-webkit-linear-gradient' + * @param {node}node + * @returns {String|undefined} */ _getValName: function(node) { if (node[0] !== 'declaration' || !node[2] || !node[2][2]) From e4fc38e4441ab59aefde1e17a286cb94c2a52290 Mon Sep 17 00:00:00 2001 From: Denis Payase Date: Mon, 11 Nov 2013 22:30:34 +0400 Subject: [PATCH 4/4] Fix typo in JSDocs --- lib/options/vendor-prefix-align.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/options/vendor-prefix-align.js b/lib/options/vendor-prefix-align.js index 3ed8a920..4b9a5840 100644 --- a/lib/options/vendor-prefix-align.js +++ b/lib/options/vendor-prefix-align.js @@ -58,7 +58,7 @@ module.exports = { * * Return property name. * e.g. - * for:'color: #fff' + * for: 'color: #fff' * returns string: 'color' * @param {node} node * @returns {String|undefined} @@ -71,13 +71,13 @@ module.exports = { /** * Internal * - * Return for value name. + * Return property value name. * e.g. * for: '-webkit-transition: -webkit-transform 150ms linear' * returns string: '-webkit-transform', and * for: 'background: -webkit-linear-gradient(...)' * returns string: '-webkit-linear-gradient' - * @param {node}node + * @param {node} node * @returns {String|undefined} */ _getValName: function(node) {