@@ -124,6 +124,23 @@ function getOrderProperty(node, order) {
124
124
return orderProperty ;
125
125
}
126
126
127
+ function addIndexesToNode ( node , index , order ) {
128
+ // Index to place the nodes that shouldn't be sorted
129
+ var lastGroupIndex = order [ '...' ] ? order [ '...' ] . group : Infinity ;
130
+ var lastPropertyIndex = order [ '...' ] ? order [ '...' ] . prop : Infinity ;
131
+
132
+ var orderProperty = getOrderProperty ( node , order ) ;
133
+
134
+ // If the declaration's property is in order's list, save its
135
+ // group and property indexes. Otherwise set them to 10000, so
136
+ // declaration appears at the bottom of a sorted list:
137
+ node . groupIndex = orderProperty && orderProperty . group > - 1 ? orderProperty . group : lastGroupIndex ;
138
+ node . propertyIndex = orderProperty && orderProperty . prop > - 1 ? orderProperty . prop : lastPropertyIndex ;
139
+ node . initialIndex = index ;
140
+
141
+ return node ;
142
+ }
143
+
127
144
function fetchAllCommentsBeforeNode ( comments , previousNode , node , currentInitialIndex ) {
128
145
if ( ! previousNode || previousNode . type !== 'comment' ) {
129
146
return comments ;
@@ -171,10 +188,6 @@ module.exports = postcss.plugin('postcss-sorting', function (opts) {
171
188
var order = getSortOrderFromOptions ( opts ) ;
172
189
var linesBetweenChildrenRules = getLinesBetweenChildrenFromOptions ( opts ) ;
173
190
174
- // Index to place the nodes that shouldn't be sorted
175
- var lastGroupIndex = order [ '...' ] ? order [ '...' ] . group : Infinity ;
176
- var lastPropertyIndex = order [ '...' ] ? order [ '...' ] . prop : Infinity ;
177
-
178
191
css . walk ( function ( rule ) {
179
192
// Process only rules and atrules with nodes
180
193
if ( ( rule . type === 'rule' || rule . type === 'atrule' ) && rule . nodes && rule . nodes . length ) {
@@ -193,14 +206,7 @@ module.exports = postcss.plugin('postcss-sorting', function (opts) {
193
206
return ;
194
207
}
195
208
196
- var orderProperty = getOrderProperty ( node , order ) ;
197
-
198
- // If the declaration's property is in order's list, save its
199
- // group and property indexes. Otherwise set them to 10000, so
200
- // declaration appears at the bottom of a sorted list:
201
- node . groupIndex = orderProperty && orderProperty . group > - 1 ? orderProperty . group : lastGroupIndex ;
202
- node . propertyIndex = orderProperty && orderProperty . prop > - 1 ? orderProperty . prop : lastPropertyIndex ;
203
- node . initialIndex = index ;
209
+ node = addIndexesToNode ( node , index , order ) ;
204
210
205
211
// If comment on separate line before node, use node's indexes for comment
206
212
var commentsBefore = fetchAllCommentsBeforeNode ( [ ] , node . prev ( ) , node ) ;
0 commit comments