@@ -6,7 +6,6 @@ module.exports = {
66 * @param {Boolean } isPrevDeclExists
77 */
88 _splitBunch : function ( bunch , isPrevDeclExists ) {
9-
109 var nextBunch = [ ] ;
1110 var declAlready = false ;
1211 var flag = false ;
@@ -15,32 +14,31 @@ module.exports = {
1514
1615 for ( var i = 0 ; i < bunch . length ; ++ i ) {
1716 if ( flag ) { nextBunch . push ( bunch [ i ] ) ; continue ; }
18- if ( bunch [ i ] [ 0 ] == 'declaration' ) { declAlready = true ; }
17+ if ( bunch [ i ] [ 0 ] === 'declaration' ) { declAlready = true ; }
1918
2019 if ( isPrevDeclExists && ! declAlready ) continue ;
21- if ( bunch [ i ] [ 0 ] != 's' ) continue ;
20+ if ( bunch [ i ] [ 0 ] !== 's' ) continue ;
2221
2322 var indexOfNewLine = bunch [ i ] [ 1 ] . indexOf ( '\n' ) ;
2423
25- if ( indexOfNewLine == - 1 ) continue ;
24+ if ( indexOfNewLine === - 1 ) continue ;
2625
2726 nextBunch . push ( [ 's' , bunch [ i ] [ 1 ] . substr ( indexOfNewLine + 1 ) ] ) ;
2827 bunch [ i ] [ 1 ] = bunch [ i ] [ 1 ] . substr ( 0 , indexOfNewLine + 1 ) ;
2928
3029 flag = i + 1 ;
3130 }
3231
33- if ( nextBunch . length == 1 && nextBunch [ 0 ] [ 0 ] == 's' ) {
32+ if ( nextBunch . length === 1 && nextBunch [ 0 ] [ 0 ] = == 's' ) {
3433 item = nextBunch [ 0 ] ;
35- indexOf = item [ 1 ] . lastIndexOf ( '\n' )
34+ indexOf = item [ 1 ] . lastIndexOf ( '\n' ) ;
3635
37- indexOf != - 1 && ( item [ 1 ] = item [ 1 ] . substr ( indexOf + 1 ) ) ;
36+ indexOf !== - 1 && ( item [ 1 ] = item [ 1 ] . substr ( indexOf + 1 ) ) ;
3837 }
3938
4039 flag && bunch . splice ( flag ) ;
4140
4241 return nextBunch ;
43-
4442 } ,
4543
4644 /**
@@ -52,31 +50,26 @@ module.exports = {
5250 * @param {node } node
5351 */
5452 _createNodeExt : function ( node ) {
55-
5653 var extNode = [ ] ;
5754 var bunch = [ ] ;
5855 var nextBunch ;
5956 var prevDeclPropertyName ;
6057
6158 node . forEach ( function ( node ) {
62-
63- if ( node [ 0 ] == 'declaration' ) {
59+ if ( node [ 0 ] === 'declaration' ) {
6460 nextBunch = this . _splitBunch ( bunch , prevDeclPropertyName ) ;
6561 extNode . push ( { data : bunch , decl : prevDeclPropertyName } ) ;
6662 bunch = nextBunch ;
6763 prevDeclPropertyName = node [ 1 ] [ 1 ] [ 1 ] ;
6864 }
69-
7065 bunch . push ( node ) ;
71-
7266 } , this ) ;
7367
7468 nextBunch = this . _splitBunch ( bunch , prevDeclPropertyName ) ;
7569 extNode . push ( { data : bunch , decl : prevDeclPropertyName } ) ;
7670 nextBunch . length && extNode . push ( { data : nextBunch } ) ;
7771
7872 return extNode ;
79-
8073 } ,
8174
8275 /**
@@ -85,16 +78,13 @@ module.exports = {
8578 * @param {extNode } extNode
8679 */
8780 _addGroupDelimiter : function ( extNodePrev , extNode ) {
88-
8981 if ( ! extNodePrev . decl || ! extNode . decl ) return ;
9082
9183 var indexA = this . _order [ extNodePrev . decl ] ;
9284 var indexB = this . _order [ extNode . decl ] ;
93- var isGroupBorder = indexA && indexB && indexA . group != indexB . group ;
94-
95- if ( isGroupBorder )
96- extNode . data . unshift ( [ 's' , '\n' ] ) ;
85+ var isGroupBorder = indexA && indexB && indexA . group !== indexB . group ;
9786
87+ if ( isGroupBorder ) extNode . data . unshift ( [ 's' , '\n' ] ) ;
9888 } ,
9989
10090 /**
@@ -103,14 +93,11 @@ module.exports = {
10393 * @param {extNode } extNode
10494 */
10595 _applyNodeExt : function ( node , extNode ) {
106-
10796 node . splice ( 0 , node . length ) ;
108-
10997 extNode . forEach ( function ( item , i ) {
11098 i > 0 && this . _addGroupDelimiter ( extNode [ i - 1 ] , item ) ;
11199 node . push . apply ( node , item . data ) ;
112100 } , this ) ;
113-
114101 } ,
115102
116103 /**
@@ -120,18 +107,16 @@ module.exports = {
120107 * @returns {Object }
121108 */
122109 setValue : function ( value ) {
123-
124110 if ( ! value ) return ;
125111
126- this . _order = { }
127- value . forEach ( function ( group , groupIndex ) {
112+ this . _order = { } ;
113+ value . forEach ( function ( group , groupIndex ) {
128114 group . forEach ( function ( prop , propIndex ) {
129115 this . _order [ prop ] = { group : groupIndex , prop : propIndex } ;
130- } , this )
116+ } , this ) ;
131117 } , this ) ;
132118
133119 return this ;
134-
135120 } ,
136121
137122 /**
@@ -140,7 +125,6 @@ module.exports = {
140125 * @param {node } node
141126 */
142127 process : function ( nodeType , node ) {
143-
144128 if ( nodeType !== 'block' ) return ;
145129
146130 var order = this . _order ;
@@ -149,21 +133,18 @@ module.exports = {
149133 var lastSymbols = nodeExt [ nodeExt . length - 1 ] . decl || nodeExt . pop ( ) ;
150134
151135 nodeExt . sort ( function ( a , b ) {
152-
153136 var indexA = order [ a . decl ] || { prop : - 1 } ;
154137 var indexB = order [ b . decl ] || { prop : - 1 } ;
155138 var groupDelta = indexA . group - indexB . group ;
156139 var propDelta = indexA . prop - indexB . prop ;
157140
158141 return groupDelta !== 0 ? groupDelta : propDelta ;
159-
160142 } ) ;
161143
162144 firstSymbols && nodeExt . unshift ( firstSymbols ) ;
163145 lastSymbols && nodeExt . push ( lastSymbols ) ;
164146
165147 this . _applyNodeExt ( node , nodeExt ) ;
166-
167148 }
168149
169150} ;
0 commit comments