@@ -26,11 +26,10 @@ module.exports = {
2626 */
2727 process : function ( nodeType , node ) {
2828 // Types of nodes that can be sorted:
29- var NODES = [ 'atruleb' , 'atruler' , 'atrules' , 'comment' , 'declaration' , 's' ] ;
30- // Special @-rules that can be sorted:
31- var ATRULES = [ 'extend' , 'import' , 'include' ] ;
29+ var NODES = [ 'atruleb' , 'atruler' , 'atrules' , 'commentML' , 'commentSL' ,
30+ 'declaration' , 's' , 'include' ] ;
3231 // Spaces and comments:
33- var SC = [ 'comment ' , 's' ] ;
32+ var SC = [ 'commentML' , 'commentSL ', 's' ] ;
3433
3534 var currentNode ;
3635 // Sort order of properties:
@@ -64,10 +63,9 @@ module.exports = {
6463
6564 for ( ; i < l ; i ++ ) {
6665 currentNode = node [ i ] ;
67- // If there is no node, or it is nor spaces neither comment ,
66+ // If there is no node left ,
6867 // stop and do nothing with previously found spaces/comments:
69- if ( ! currentNode ||
70- NODES . indexOf ( currentNode [ 0 ] ) === - 1 ) {
68+ if ( ! currentNode ) {
7169 return false ;
7270 }
7371
@@ -104,7 +102,7 @@ module.exports = {
104102 // If there is no node, or it is nor spaces neither comment, stop:
105103 if ( ! currentNode || SC . indexOf ( currentNode [ 0 ] ) === - 1 ) break ;
106104
107- if ( currentNode [ 0 ] === 'comment' ) {
105+ if ( [ 'commentML' , 'commentSL' ] . indexOf ( currentNode [ 0 ] ) > - 1 ) {
108106 sc . push ( currentNode ) ;
109107 d . push ( i + 1 ) ;
110108 continue ;
@@ -166,15 +164,15 @@ module.exports = {
166164
167165 // If there is `;` right after the declaration, save it with the
168166 // declaration and mark it for removing from parent node:
169- if ( currentNode && nextNode [ 0 ] === 'decldelim' ) {
167+ if ( currentNode && nextNode && nextNode [ 0 ] === 'decldelim' ) {
170168 extendedNode . delim . push ( nextNode ) ;
171169 deleted . push ( i + 1 ) ;
172170 i ++ ;
173171 }
174172
175173 // Save spaces and comments which follow right after the declaration
176174 // and mark them for removing from parent node:
177- extendedNode . sc1 = checkSC1 ( i ) ;
175+ extendedNode . sc1 = checkSC1 ( ) ;
178176
179177 return extendedNode ;
180178 } ;
@@ -207,17 +205,21 @@ module.exports = {
207205 // with a valid property (e.g. `color` or `$width`).
208206 // If not, proceed with the next node:
209207 propertyName = null ;
210- for ( j = 1 , nl = node [ i ] . length ; j < nl ; j ++ ) {
211- currentNode = node [ i ] [ j ] ;
212- if ( currentNode [ 0 ] === 'property' ) {
213- propertyName = currentNode [ 1 ] [ 0 ] === 'variable' ?
214- '$variable' : currentNode [ 1 ] [ 1 ] ;
215- break ;
216- } else if ( currentNode [ 0 ] === 'atkeyword' ) {
217- if ( ATRULES . indexOf ( currentNode [ 1 ] [ 1 ] ) > - 1 ) {
218- propertyName = '$' + currentNode [ 1 ] [ 1 ] ;
208+ // Look for includes:
209+ if ( node [ i ] [ 0 ] === 'include' ) {
210+ propertyName = '$include' ;
211+ } else {
212+ for ( j = 1 , nl = node [ i ] . length ; j < nl ; j ++ ) {
213+ currentNode = node [ i ] [ j ] ;
214+ if ( currentNode [ 0 ] === 'property' ) {
215+ propertyName = currentNode [ 1 ] [ 0 ] === 'variable' ?
216+ '$variable' : currentNode [ 1 ] [ 1 ] ;
217+ break ;
218+ } else if ( currentNode [ 0 ] === 'atkeyword' &&
219+ currentNode [ 1 ] [ 1 ] === 'import' ) { // Look for imports
220+ propertyName = '$import' ;
221+ break ;
219222 }
220- break ;
221223 }
222224 }
223225
0 commit comments