Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/options/sort-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ module.exports = {
return false;
}

// Remove any empty lines:
if (currentNode[0] === 's') {
currentNode[1] = currentNode[1].replace(/\n[\s\t\n\r]*\n/, '\n');
}

// If the node is declaration or @-rule, stop and return all
// found nodes with spaces and comments (if there are any):
if (SC.indexOf(currentNode[0]) === -1) break;
Expand Down Expand Up @@ -102,6 +107,11 @@ module.exports = {
// If there is no node, or it is nor spaces neither comment, stop:
if (!currentNode || SC.indexOf(currentNode[0]) === -1) break;

// Remove any empty lines:
if (currentNode[0] === 's') {
currentNode[1] = currentNode[1].replace(/\n[\s\t\n\r]*\n/, '\n');
}

if (['commentML', 'commentSL'].indexOf(currentNode[0]) > -1) {
sc.push(currentNode);
d.push(i + 1);
Expand Down Expand Up @@ -146,6 +156,7 @@ module.exports = {
var orderProperty = order[propertyName];

extendedNode = {
i: i,
node: currentNode,
sc0: sc0,
delim: []
Expand Down Expand Up @@ -249,7 +260,12 @@ module.exports = {
// If a and b have the same group index, and a's property index is
// higher than b's property index, in a sorted list a appears after
// b:
return a.propertyIndex - b.propertyIndex;
if (a.propertyIndex !== b.propertyIndex) return a.propertyIndex - b.propertyIndex;

// If a and b have the same group index and the same property index,
// in a sorted list they appear in the same order they were in
// original array:
return a.i - b.i;
});

// Build all nodes back together. First go sorted declarations, then
Expand Down
1 change: 0 additions & 1 deletion test/integral.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
background: -moz-linear-gradient(top, rgba(0,0,0,.2) 0, rgba(0,0,0,.4) 100%);
background: -o-linear-gradient(top, rgba(0,0,0,.2) 0,rgba(0,0,0,.4) 100%);
background: linear-gradient(to bottom, rgba(0,0,0,.2) 0,rgba(0,0,0,.4) 100%);

-moz-box-shadow: 0 1px 0 rgba(0,0,0,.07);
box-shadow: 0 1px 0 rgba(0,0,0,.07);
}
Expand Down
30 changes: 30 additions & 0 deletions test/sort-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,34 @@ describe('options/sort-order', function() {
assert.equal(input, expected);

});

it('Issue 94. Test 1', function() {
var config = comb.getConfig('csscomb');

var input = readFile('issue-94-1.css');
var expected = readFile('issue-94-1.expected.css');

comb.configure(config);
assert.equal(comb.processString(input), expected);
});

it('Issue 94. Test 2', function() {
var config = comb.getConfig('csscomb');

var input = readFile('issue-94-2.css');
var expected = readFile('issue-94-2.expected.css');

comb.configure(config);
assert.equal(comb.processString(input), expected);
});

it('Issue 94. Test 3', function() {
var config = comb.getConfig('csscomb');

var input = readFile('issue-94-3.css');
var expected = readFile('issue-94-3.expected.css');

comb.configure(config);
assert.equal(comb.processString(input), expected);
});
});
18 changes: 18 additions & 0 deletions test/sort-order/issue-94-1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.test
{
position: absolute;
top: -1px;
right: -1px;
bottom: -1px;
left: -1px;

border: 1px solid transparent;
border-color: rgba(0,0,0,0.38) rgba(0,0,0,0.27) rgba(0,0,0,0.16);

background: -webkit-linear-gradient(#fff, #fff);
background: linear-gradient(#fff, #fff);
background-clip: padding-box;
background-size: 16px 16px;

-webkit-appearance: textfield;
}
17 changes: 17 additions & 0 deletions test/sort-order/issue-94-1.expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.test
{
position: absolute;
top: -1px;
right: -1px;
bottom: -1px;
left: -1px;

border: 1px solid transparent;
border-color: rgba(0,0,0,.38) rgba(0,0,0,.27) rgba(0,0,0,.16);
background: -webkit-linear-gradient(#fff, #fff);
background: linear-gradient(#fff, #fff);
background-clip: padding-box;
background-size: 16px 16px;

-webkit-appearance: textfield;
}
19 changes: 19 additions & 0 deletions test/sort-order/issue-94-2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.test
{
width: 0;
width: 100%;
height: 0;

background: #fff;
color: #000;

display: -moz-inline-stack;
display: inline-block;

position: absolute;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
19 changes: 19 additions & 0 deletions test/sort-order/issue-94-2.expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.test
{
position: absolute;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;

display: -moz-inline-stack;
display: inline-block;

width: 0;
width: 100%;
height: 0;

color: #000;
background: #fff;
}
21 changes: 21 additions & 0 deletions test/sort-order/issue-94-3.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.input-view {
position: absolute;
-webkit-appearance: none;
right: -1px;
bottom: -1px;
left: -1px;

border: 1px solid transparent;

top: -1px;

background: -webkit-linear-gradient(#FFF, #FFF);
background: linear-gradient(#FFF, #FFF);
background-clip: padding-box;
background-size: 16px 16px;
box-shadow: 0 1px 0 rgba(255,255,255,0.2), inset 0 1px 1px rgba(0,0,0,0.1);

border-color: rgba(0,0,0,0.27);
border-top-color: rgba(0,0,0,0.38);
border-bottom-color: rgba(0,0,0,0.16);
}
20 changes: 20 additions & 0 deletions test/sort-order/issue-94-3.expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.input-view
{
position: absolute;
top: -1px;
right: -1px;
bottom: -1px;
left: -1px;

border: 1px solid transparent;
border-color: rgba(0,0,0,.27);
border-top-color: rgba(0,0,0,.38);
border-bottom-color: rgba(0,0,0,.16);
background: -webkit-linear-gradient(#fff, #fff);
background: linear-gradient(#fff, #fff);
background-clip: padding-box;
background-size: 16px 16px;
box-shadow: 0 1px 0 rgba(255,255,255,.2), inset 0 1px 1px rgba(0,0,0,.1);

-webkit-appearance: none;
}