1- var cssp = require ( 'cssp ' ) ;
1+ var gonzales = require ( 'gonzales ' ) ;
22var minimatch = require ( 'minimatch' ) ;
33var vow = require ( 'vow' ) ;
44var vfs = require ( 'vow-fs' ) ;
@@ -11,11 +11,12 @@ var vfs = require('vow-fs');
1111var Comb = function ( ) {
1212 this . _handlers ;
1313 this . _options = [
14+ 'always-semicolon' ,
1415 'strip-spaces' ,
1516 'stick-brace' ,
1617 'colon-space' ,
1718 'rule-indent' ,
18- 'always-semicolon ' ,
19+ 'block-indent ' ,
1920 'sort-order'
2021 ] ;
2122 this . _config = { } ;
@@ -54,23 +55,25 @@ Comb.prototype = {
5455 * @returns {Array }
5556 */
5657 processTree : function ( tree ) {
57- this . processNode ( [ 'tree' , tree ] ) ;
58+ this . processNode ( [ 'tree' , tree ] , 0 ) ;
5859 return tree ;
5960 } ,
6061
6162 /**
6263 * Processes tree node.
6364 * @param {Array } node Tree node
65+ * @param {Number } level Indent level
6466 */
6567 processNode : function ( node , level ) {
6668 var _this = this ;
6769 node . forEach ( function ( node ) {
6870 if ( ! Array . isArray ( node ) ) return ;
6971 var nodeType = node . shift ( ) ;
7072 _this . _handlers . forEach ( function ( handler ) {
71- handler . process ( nodeType , node ) ;
73+ handler . process ( nodeType , node , level ) ;
7274 } ) ;
7375 node . unshift ( nodeType ) ;
76+ if ( nodeType === 'atrulers' ) level ++ ;
7477 _this . processNode ( node , level ) ;
7578 } ) ;
7679 } ,
@@ -82,12 +85,20 @@ Comb.prototype = {
8285 */
8386 processString : function ( text , filename ) {
8487 var tree ;
88+ var string = JSON . stringify ;
89+ if ( typeof text === 'undefined' ) {
90+ throw new Error ( 'Undefined file content ' + filename + ': ' + string ( text ) ) ;
91+ }
8592 try {
86- tree = this . processTree ( cssp . parse ( text ) ) ;
93+ tree = gonzales . srcToCSSP ( text ) ;
8794 } catch ( e ) {
8895 throw new Error ( 'Parsing error at ' + filename + ': ' + e . message ) ;
8996 }
90- return cssp . translate ( tree ) ;
97+ if ( typeof tree === 'undefined' ) {
98+ throw new Error ( 'Undefined tree at ' + filename + ': ' + string ( text ) + ' => ' + string ( tree ) ) ;
99+ }
100+ tree = this . processTree ( tree ) ;
101+ return gonzales . csspToSrc ( tree ) ;
91102 } ,
92103
93104 /**
@@ -117,18 +128,17 @@ Comb.prototype = {
117128 return vfs . listDir ( path ) . then ( function ( filenames ) {
118129 return vow . all ( filenames . map ( function ( filename ) {
119130 var fullname = path + '/' + filename ;
120- return vfs . stat ( fullname ) . then ( function ( stat ) {
121- if ( _this . _shouldProcess ( fullname ) ) {
131+ if ( _this . _shouldProcess ( fullname ) ) {
132+ return vfs . stat ( fullname ) . then ( function ( stat ) {
122133 if ( stat . isDirectory ( ) ) {
123134 return _this . processDirectory ( fullname ) ;
124135 } else if ( fullname . match ( / \. c s s $ / ) ) {
125136 return vow . when ( _this . processFile ( fullname ) ) . then ( function ( errors ) {
126137 if ( errors ) return errors ;
127138 } ) ;
128139 }
129- }
130- return ;
131- } ) ;
140+ } ) ;
141+ }
132142 } ) ) . then ( function ( results ) {
133143 return [ ] . concat . apply ( [ ] , results ) ;
134144 } ) ;
0 commit comments