@@ -56,25 +56,37 @@ module.exports = {
5656 /**
5757 * Internal
5858 *
59- * Selector for property name.
60- * @param {node } item
61- * @returns {String|false|undefined }
59+ * Return property name.
60+ * e.g.
61+ * for: 'color: #fff'
62+ * returns string: 'color'
63+ * @param {node } node
64+ * @returns {String|undefined }
6265 */
63- _declName : function ( item ) {
64- return item [ 0 ] === 'declaration' && item [ 1 ] [ 1 ] [ 1 ] ;
66+ _getDeclName : function ( node ) {
67+ if ( node [ 0 ] !== 'declaration' ) return ;
68+ return node [ 1 ] [ 1 ] [ 1 ] ;
6569 } ,
6670
6771 /**
6872 * Internal
6973 *
70- * Selector for value name.
71- * @param {node } item
72- * @returns {String|false|undefined }
74+ * Return property value name.
75+ * e.g.
76+ * for: '-webkit-transition: -webkit-transform 150ms linear'
77+ * returns string: '-webkit-transform', and
78+ * for: 'background: -webkit-linear-gradient(...)'
79+ * returns string: '-webkit-linear-gradient'
80+ * @param {node } node
81+ * @returns {String|undefined }
7382 */
74- _valName : function ( item ) {
75- return item [ 0 ] === 'declaration' && item [ 2 ] && item [ 2 ] [ 2 ] &&
76- item [ 2 ] [ 2 ] [ 0 ] === 'funktion' && item [ 2 ] [ 2 ] [ 1 ] [ 0 ] === 'ident' &&
77- item [ 2 ] [ 2 ] [ 1 ] [ 1 ] ;
83+ _getValName : function ( node ) {
84+ if ( node [ 0 ] !== 'declaration' || ! node [ 2 ] || ! node [ 2 ] [ 2 ] )
85+ return ;
86+ if ( node [ 2 ] [ 2 ] [ 0 ] === 'ident' )
87+ return node [ 2 ] [ 2 ] [ 1 ] ;
88+ if ( node [ 2 ] [ 2 ] [ 0 ] === 'funktion' )
89+ return node [ 2 ] [ 2 ] [ 1 ] [ 1 ] ;
7890 } ,
7991
8092 /**
@@ -140,18 +152,18 @@ module.exports = {
140152 var _this = this ;
141153
142154 // Gathering Info
143- this . _walk ( node , this . _declName , function ( info , i ) {
155+ this . _walk ( node , this . _getDeclName , function ( info , i ) {
144156 _this . _updateDict ( info , dict , node [ i - 1 ] [ 1 ] ) ;
145157 } ) ;
146- this . _walk ( node , this . _valName , function ( info , i ) {
158+ this . _walk ( node , this . _getValName , function ( info , i ) {
147159 _this . _updateDict ( info , dict , node [ i ] [ 2 ] [ 1 ] [ 1 ] ) ;
148160 } ) ;
149161
150162 // Update nodes
151- this . _walk ( node , this . _declName , function ( info , i ) {
163+ this . _walk ( node , this . _getDeclName , function ( info , i ) {
152164 node [ i - 1 ] [ 1 ] = _this . _updateIndent ( info , dict , node [ i - 1 ] [ 1 ] ) ;
153165 } ) ;
154- this . _walk ( node , this . _valName , function ( info , i ) {
166+ this . _walk ( node , this . _getValName , function ( info , i ) {
155167 node [ i ] [ 2 ] [ 1 ] [ 1 ] = _this . _updateIndent ( info , dict , node [ i ] [ 2 ] [ 1 ] [ 1 ] ) ;
156168 } ) ;
157169 }
0 commit comments