Skip to content

Commit c5147c1

Browse files
committed
Merge pull request #101 from L0stSoul/dev
Fix issue #98
2 parents cc8d964 + e4fc38e commit c5147c1

4 files changed

Lines changed: 45 additions & 17 deletions

File tree

lib/options/vendor-prefix-align.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,37 @@ module.exports = {
5656
/**
5757
* Internal
5858
*
59-
* Selector for property name.
60-
* @param {node} item
61-
* @returns {String|false|undefined}
59+
* Return property name.
60+
* e.g.
61+
* for: 'color: #fff'
62+
* returns string: 'color'
63+
* @param {node} node
64+
* @returns {String|undefined}
6265
*/
63-
_declName: function(item) {
64-
return item[0] === 'declaration' && item[1][1][1];
66+
_getDeclName: function(node) {
67+
if (node[0] !== 'declaration') return;
68+
return node[1][1][1];
6569
},
6670

6771
/**
6872
* Internal
6973
*
70-
* Selector for value name.
71-
* @param {node} item
72-
* @returns {String|false|undefined}
74+
* Return property value name.
75+
* e.g.
76+
* for: '-webkit-transition: -webkit-transform 150ms linear'
77+
* returns string: '-webkit-transform', and
78+
* for: 'background: -webkit-linear-gradient(...)'
79+
* returns string: '-webkit-linear-gradient'
80+
* @param {node} node
81+
* @returns {String|undefined}
7382
*/
74-
_valName: function(item) {
75-
return item[0] === 'declaration' && item[2] && item[2][2] &&
76-
item[2][2][0] === 'funktion' && item[2][2][1][0] === 'ident' &&
77-
item[2][2][1][1];
83+
_getValName: function(node) {
84+
if (node[0] !== 'declaration' || !node[2] || !node[2][2])
85+
return;
86+
if (node[2][2][0] === 'ident')
87+
return node[2][2][1];
88+
if (node[2][2][0] === 'funktion')
89+
return node[2][2][1][1];
7890
},
7991

8092
/**
@@ -140,18 +152,18 @@ module.exports = {
140152
var _this = this;
141153

142154
// Gathering Info
143-
this._walk(node, this._declName, function(info, i) {
155+
this._walk(node, this._getDeclName, function(info, i) {
144156
_this._updateDict(info, dict, node[i - 1][1]);
145157
});
146-
this._walk(node, this._valName, function(info, i) {
158+
this._walk(node, this._getValName, function(info, i) {
147159
_this._updateDict(info, dict, node[i][2][1][1]);
148160
});
149161

150162
// Update nodes
151-
this._walk(node, this._declName, function(info, i) {
163+
this._walk(node, this._getDeclName, function(info, i) {
152164
node[i - 1][1] = _this._updateIndent(info, dict, node[i - 1][1]);
153165
});
154-
this._walk(node, this._valName, function(info, i) {
166+
this._walk(node, this._getValName, function(info, i) {
155167
node[i][2][1][1] = _this._updateIndent(info, dict, node[i][2][1][1]);
156168
});
157169
}

test/vendor-prefix-align.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@ describe('options/vendor-prefix-align', function() {
3535
assert.equal(comb.processString(input), expected);
3636
});
3737

38+
it('Should correct align prefixes in preoperties and values at the same time', function() {
39+
var input = fs.readFileSync('./test/vendor-prefix-align/both.css', 'utf8');
40+
var expected = fs.readFileSync('./test/vendor-prefix-align/both.expected.css', 'utf8');
41+
42+
assert.equal(comb.processString(input), expected);
43+
});
44+
3845
it('Should always correctly align prefixes', function() {
3946
var input = fs.readFileSync('./test/vendor-prefix-align/complex.css', 'utf8');
4047
var expected = fs.readFileSync('./test/vendor-prefix-align/complex.expected.css', 'utf8');
4148

4249
assert.equal(comb.processString(input), expected);
4350
});
44-
4551
});

test/vendor-prefix-align/both.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.serp-block__head_animation_yes
2+
{
3+
-webkit-transition: -webkit-transform 150ms linear;
4+
transition: transform 150ms linear;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.serp-block__head_animation_yes
2+
{
3+
-webkit-transition: -webkit-transform 150ms linear;
4+
transition: transform 150ms linear;
5+
}

0 commit comments

Comments
 (0)