@@ -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
0 commit comments