Skip to content

Commit 903ee30

Browse files
committed
Merge pull request #130 from csscomb/tg/94-sort-order
Sort order of properties with the same index (#94)
2 parents 0f352bf + 71029c1 commit 903ee30

9 files changed

Lines changed: 161 additions & 2 deletions

File tree

lib/options/sort-order.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ module.exports = {
7676
return false;
7777
}
7878

79+
// Remove any empty lines:
80+
if (currentNode[0] === 's') {
81+
currentNode[1] = currentNode[1].replace(/\n[\s\t\n\r]*\n/, '\n');
82+
}
83+
7984
// If the node is declaration or @-rule, stop and return all
8085
// found nodes with spaces and comments (if there are any):
8186
if (SC.indexOf(currentNode[0]) === -1) break;
@@ -109,6 +114,11 @@ module.exports = {
109114
// If there is no node, or it is nor spaces neither comment, stop:
110115
if (!currentNode || SC.indexOf(currentNode[0]) === -1) break;
111116

117+
// Remove any empty lines:
118+
if (currentNode[0] === 's') {
119+
currentNode[1] = currentNode[1].replace(/\n[\s\t\n\r]*\n/, '\n');
120+
}
121+
112122
if (['commentML', 'commentSL'].indexOf(currentNode[0]) > -1) {
113123
sc.push(currentNode);
114124
d.push(i + 1);
@@ -153,6 +163,7 @@ module.exports = {
153163
var orderProperty = order[propertyName];
154164

155165
extendedNode = {
166+
i: i,
156167
node: currentNode,
157168
sc0: sc0,
158169
delim: []
@@ -256,7 +267,12 @@ module.exports = {
256267
// If a and b have the same group index, and a's property index is
257268
// higher than b's property index, in a sorted list a appears after
258269
// b:
259-
return a.propertyIndex - b.propertyIndex;
270+
if (a.propertyIndex !== b.propertyIndex) return a.propertyIndex - b.propertyIndex;
271+
272+
// If a and b have the same group index and the same property index,
273+
// in a sorted list they appear in the same order they were in
274+
// original array:
275+
return a.i - b.i;
260276
});
261277

262278
// Build all nodes back together. First go sorted declarations, then

test/integral.expect.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
background: -moz-linear-gradient(top, rgba(0,0,0,.2) 0, rgba(0,0,0,.4) 100%);
99
background: -o-linear-gradient(top, rgba(0,0,0,.2) 0,rgba(0,0,0,.4) 100%);
1010
background: linear-gradient(to bottom, rgba(0,0,0,.2) 0,rgba(0,0,0,.4) 100%);
11-
1211
-moz-box-shadow: 0 1px 0 rgba(0,0,0,.07);
1312
box-shadow: 0 1px 0 rgba(0,0,0,.07);
1413
}

test/sort-order.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,34 @@ describe('options/sort-order', function() {
130130
assert.equal(input, expected);
131131

132132
});
133+
134+
it('Issue 94. Test 1', function() {
135+
var config = comb.getConfig('csscomb');
136+
137+
var input = readFile('issue-94-1.css');
138+
var expected = readFile('issue-94-1.expected.css');
139+
140+
comb.configure(config);
141+
assert.equal(comb.processString(input), expected);
142+
});
143+
144+
it('Issue 94. Test 2', function() {
145+
var config = comb.getConfig('csscomb');
146+
147+
var input = readFile('issue-94-2.css');
148+
var expected = readFile('issue-94-2.expected.css');
149+
150+
comb.configure(config);
151+
assert.equal(comb.processString(input), expected);
152+
});
153+
154+
it('Issue 94. Test 3', function() {
155+
var config = comb.getConfig('csscomb');
156+
157+
var input = readFile('issue-94-3.css');
158+
var expected = readFile('issue-94-3.expected.css');
159+
160+
comb.configure(config);
161+
assert.equal(comb.processString(input), expected);
162+
});
133163
});

test/sort-order/issue-94-1.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.test
2+
{
3+
position: absolute;
4+
top: -1px;
5+
right: -1px;
6+
bottom: -1px;
7+
left: -1px;
8+
9+
border: 1px solid transparent;
10+
border-color: rgba(0,0,0,0.38) rgba(0,0,0,0.27) rgba(0,0,0,0.16);
11+
12+
background: -webkit-linear-gradient(#fff, #fff);
13+
background: linear-gradient(#fff, #fff);
14+
background-clip: padding-box;
15+
background-size: 16px 16px;
16+
17+
-webkit-appearance: textfield;
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.test
2+
{
3+
position: absolute;
4+
top: -1px;
5+
right: -1px;
6+
bottom: -1px;
7+
left: -1px;
8+
9+
border: 1px solid transparent;
10+
border-color: rgba(0,0,0,.38) rgba(0,0,0,.27) rgba(0,0,0,.16);
11+
background: -webkit-linear-gradient(#fff, #fff);
12+
background: linear-gradient(#fff, #fff);
13+
background-clip: padding-box;
14+
background-size: 16px 16px;
15+
16+
-webkit-appearance: textfield;
17+
}

test/sort-order/issue-94-2.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.test
2+
{
3+
width: 0;
4+
width: 100%;
5+
height: 0;
6+
7+
background: #fff;
8+
color: #000;
9+
10+
display: -moz-inline-stack;
11+
display: inline-block;
12+
13+
position: absolute;
14+
position: fixed;
15+
top: 0;
16+
right: 0;
17+
bottom: 0;
18+
left: 0;
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.test
2+
{
3+
position: absolute;
4+
position: fixed;
5+
top: 0;
6+
right: 0;
7+
bottom: 0;
8+
left: 0;
9+
10+
display: -moz-inline-stack;
11+
display: inline-block;
12+
13+
width: 0;
14+
width: 100%;
15+
height: 0;
16+
17+
color: #000;
18+
background: #fff;
19+
}

test/sort-order/issue-94-3.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.input-view {
2+
position: absolute;
3+
-webkit-appearance: none;
4+
right: -1px;
5+
bottom: -1px;
6+
left: -1px;
7+
8+
border: 1px solid transparent;
9+
10+
top: -1px;
11+
12+
background: -webkit-linear-gradient(#FFF, #FFF);
13+
background: linear-gradient(#FFF, #FFF);
14+
background-clip: padding-box;
15+
background-size: 16px 16px;
16+
box-shadow: 0 1px 0 rgba(255,255,255,0.2), inset 0 1px 1px rgba(0,0,0,0.1);
17+
18+
border-color: rgba(0,0,0,0.27);
19+
border-top-color: rgba(0,0,0,0.38);
20+
border-bottom-color: rgba(0,0,0,0.16);
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.input-view
2+
{
3+
position: absolute;
4+
top: -1px;
5+
right: -1px;
6+
bottom: -1px;
7+
left: -1px;
8+
9+
border: 1px solid transparent;
10+
border-color: rgba(0,0,0,.27);
11+
border-top-color: rgba(0,0,0,.38);
12+
border-bottom-color: rgba(0,0,0,.16);
13+
background: -webkit-linear-gradient(#fff, #fff);
14+
background: linear-gradient(#fff, #fff);
15+
background-clip: padding-box;
16+
background-size: 16px 16px;
17+
box-shadow: 0 1px 0 rgba(255,255,255,.2), inset 0 1px 1px rgba(0,0,0,.1);
18+
19+
-webkit-appearance: none;
20+
}

0 commit comments

Comments
 (0)