1+ var gonzales = require ( 'gonzales-pe' ) ;
2+
13module . exports = ( function ( ) {
24 // Vendor prefixes list:
35 var PREFIXES = [
@@ -73,30 +75,27 @@ module.exports = (function() {
7375 for ( var i = nodes . length ; i -- ; ) {
7476 node = nodes [ i ] ;
7577
76- if ( ! Array . isArray ( node ) )
77- continue ;
78-
79- if ( ! node [ 1 ] ) {
78+ if ( ! node . content ) {
8079 crPos = - 1 ;
8180 } else {
82- crPos = node [ 1 ] . lastIndexOf ( '\n' ) ;
83- tabPos = node [ 1 ] . lastIndexOf ( '\t' ) ;
81+ crPos = node . content . lastIndexOf ( '\n' ) ;
82+ tabPos = node . content . lastIndexOf ( '\t' ) ;
8483 if ( tabPos > crPos ) crPos = tabPos ;
8584 }
8685
8786 if ( crPos !== - 1 )
8887 oneline = false ;
8988
90- if ( node [ 0 ] === 's' ) {
91- result += node [ 1 ] . length - crPos - 1 ;
89+ if ( node . is ( 's' ) ) {
90+ result += node . content . length - crPos - 1 ;
9291 if ( crPos !== - 1 )
9392 break ;
9493 }
95- if ( node [ 0 ] === 'commentML' ) {
94+ if ( node . is ( 'commentML' ) ) {
9695 if ( crPos === - 1 ) {
97- result += node [ 1 ] . length + 4 /* comment symbols length */ ;
96+ result += node . content . length + 4 /* comment symbols length */ ;
9897 } else {
99- result += node [ 1 ] . length - crPos + 1 /* only last comment symbols length - 1(not count \n)*/ ;
98+ result += node . content . length - crPos + 1 /* only last comment symbols length - 1(not count \n)*/ ;
10099 break ;
101100 }
102101 }
@@ -114,9 +113,9 @@ module.exports = (function() {
114113 function extraIndentProperty ( nodes , i ) {
115114 var subset = [ ] ;
116115 while ( i -- ) {
117- if ( ! nodes [ i ] || nodes [ i ] [ 0 ] === 'declDelim' )
116+ if ( ! nodes . get ( i ) || nodes . get ( i ) . is ( 'declDelim' ) )
118117 break ;
119- subset . unshift ( nodes [ i ] ) ;
118+ subset . unshift ( nodes . get ( i ) ) ;
120119 }
121120 return extraIndent ( subset ) ;
122121 }
@@ -129,15 +128,16 @@ module.exports = (function() {
129128 */
130129 function extraIndentVal ( nodes , i ) {
131130 var subset = [ ] ;
132- var declaration = nodes [ i ] ;
131+ var declaration = nodes . get ( i ) ;
132+ if ( ! declaration . is ( 'declaration' ) ) return ;
133133
134134 for ( var x = declaration . length ; x -- ; ) {
135- if ( declaration [ x ] [ 0 ] !== 'value' ) continue ;
135+ if ( ! declaration . get ( x ) . is ( 'value' ) ) continue ;
136136
137137 x -- ;
138138
139- while ( declaration [ x ] [ 0 ] !== 'propertyDelim' ) {
140- subset . push ( declaration [ x ] ) ;
139+ while ( ! declaration . get ( x ) . is ( 'propertyDelim' ) ) {
140+ subset . push ( declaration . get ( x ) ) ;
141141 x -- ;
142142 }
143143
@@ -161,11 +161,10 @@ module.exports = (function() {
161161 function walk ( args ) {
162162 args . node . forEach ( function ( item , i ) {
163163 var name = args . selector ( item ) ;
164- var info = name && getPrefixInfo (
165- name ,
166- args . namespaceSelector && makeNamespace ( args . namespaceSelector ( item ) ) ,
167- args . getExtraSymbols ( args . node , i )
168- ) ;
164+ var namespace = args . namespaceSelector && makeNamespace ( args . namespaceSelector ( item ) ) ;
165+ var extraSymbols = args . getExtraSymbols ( args . node , i ) ;
166+
167+ var info = name && getPrefixInfo ( name , namespace , extraSymbols ) ;
169168 if ( ! info ) return ;
170169 args . payload ( info , i ) ;
171170 } ) ;
@@ -181,9 +180,9 @@ module.exports = (function() {
181180 * @returns {String|undefined }
182181 */
183182 function getPropertyName ( node ) {
184- if ( node [ 0 ] !== 'declaration' ) return ;
183+ if ( ! node . is ( 'declaration' ) ) return ;
185184 // TODO: Check that it's not a variable
186- return node [ 1 ] [ 1 ] [ 1 ] ;
185+ return node . get ( 0 ) . get ( 0 ) . content ;
187186 }
188187
189188 /**
@@ -198,21 +197,11 @@ module.exports = (function() {
198197 * @returns {String|undefined }
199198 */
200199 function getValName ( node ) {
201- if ( node [ 0 ] !== 'declaration' ) return ;
202-
203- var valueNode ;
204- var value ;
205-
206- for ( var i = node . length ; i -- ; ) {
207- valueNode = node [ i ] ;
208-
209- if ( valueNode [ 0 ] !== 'value' ) continue ;
200+ if ( ! node . is ( 'declaration' ) ) return ;
210201
211- value = valueNode [ 1 ] ;
212-
213- if ( value [ 0 ] === 'ident' ) return value [ 1 ] ;
214- if ( value [ 0 ] === 'function' ) return value [ 1 ] [ 1 ] ;
215- }
202+ var value = node . first ( 'value' ) ;
203+ if ( value . get ( 0 ) . is ( 'ident' ) ) return value . get ( 0 ) . content ;
204+ if ( value . get ( 0 ) . is ( 'function' ) ) return value . get ( 0 ) . get ( 0 ) . content ;
216205 }
217206
218207 /**
@@ -271,11 +260,10 @@ module.exports = (function() {
271260 /**
272261 * Processes tree node.
273262 *
274- * @param {String } nodeType
275263 * @param {node } node
276264 */
277- process : function ( nodeType , node ) {
278- if ( nodeType !== 'block' ) return ;
265+ process : function ( node ) {
266+ if ( ! node . is ( 'block' ) ) return ;
279267 oneline = true ;
280268
281269 var dict = { } ;
@@ -309,16 +297,17 @@ module.exports = (function() {
309297 namespaceSelector : getPropertyName ,
310298 getExtraSymbols : extraIndentVal ,
311299 payload : function ( info , i ) {
312- for ( var x = node [ i ] . length ; x -- ; ) {
313- if ( node [ i ] [ x ] [ 0 ] === 'value' ) break ;
300+ for ( var x = node . get ( i ) . length ; x -- ; ) {
301+ if ( node . get ( i ) . get ( x ) . is ( 'value' ) ) break ;
314302 }
315303
316- if ( node [ i ] [ x - 1 ] [ 0 ] !== 's' ) {
317- node [ i ] . splice ( x , 0 , [ 's' , '' ] ) ;
304+ if ( ! node . get ( i ) . get ( x - 1 ) . is ( 's' ) ) {
305+ var space = gonzales . createNode ( { type : 's' , content : '' } ) ;
306+ node . get ( i ) . insert ( x , space ) ;
318307 ++ x ;
319308 }
320309
321- node [ i ] [ x - 1 ] [ 1 ] = updateIndent ( info , dict , node [ i ] [ x - 1 ] [ 1 ] ) ;
310+ node . get ( i ) . get ( x - 1 ) . content = updateIndent ( info , dict , node . get ( i ) . get ( x - 1 ) . content ) ;
322311 }
323312 } ) ;
324313
@@ -329,15 +318,15 @@ module.exports = (function() {
329318 selector : getPropertyName ,
330319 getExtraSymbols : extraIndentProperty ,
331320 payload : function ( info , i ) {
332- // `node[ i - 1] ` can be either space or comment:
333- var whitespaceNode = node [ i - 1 ] ;
321+ // `node.get( i - 1) ` can be either space or comment:
322+ var whitespaceNode = node . get ( i - 1 ) ;
334323 if ( ! whitespaceNode ) return ;
335324 // If it's a comment, insert an empty space node:
336- if ( whitespaceNode [ 0 ] !== 's' ) {
337- whitespaceNode = [ 's' , '' ] ;
338- node . splice ( i - 1 , 0 , whitespaceNode ) ;
325+ if ( ! whitespaceNode . is ( 's' ) ) {
326+ whitespaceNode = gonzales . createNode ( { type : 's' , content : '' } ) ;
327+ node . insert ( i - 1 , whitespaceNode ) ;
339328 }
340- whitespaceNode [ 1 ] = updateIndent ( info , dict , whitespaceNode [ 1 ] ) ;
329+ whitespaceNode . content = updateIndent ( info , dict , whitespaceNode . content ) ;
341330 }
342331 } ) ;
343332 } ,
0 commit comments