@@ -222,69 +222,43 @@ const analyze = (css) => {
222222 }
223223 break
224224 }
225- case 'Declaration' : {
226- totalDeclarations ++
227-
228- const declaration = stringifyNode ( node )
229- if ( declarationsCache [ declaration ] ) {
230- declarationsCache [ declaration ] ++
231- } else {
232- declarationsCache [ declaration ] = 1
233- }
234-
235- if ( node . important ) {
236- importantDeclarations ++
237-
238- if ( this . atrule && endsWith ( 'keyframes' , this . atrule . name ) ) {
239- importantsInKeyframes ++
240- }
241- }
225+ case 'Value' : {
226+ values . push ( node )
242227
243- const { value, property } = node
244-
245- properties . push ( property )
246- values . push ( value )
247-
248- if ( hasVendorPrefix ( property ) ) {
249- propertyVendorPrefixes . push ( property )
250- } else if ( isHack ( property ) ) {
251- propertyHacks . push ( property )
252- } else if ( isCustom ( property ) ) {
253- customProperties . push ( property )
254- }
228+ const property = this . declaration . property
255229
256230 // Process properties first that don't have colors,
257231 // so we can avoid further walking them;
258232 if ( isProperty ( 'z-index' , property ) ) {
259- zindex . push ( value )
233+ zindex . push ( node )
260234 return this . skip
261235 } else if ( isProperty ( 'font' , property ) ) {
262- fontValues . push ( value )
236+ fontValues . push ( node )
263237 break
264238 } else if ( isProperty ( 'font-size' , property ) ) {
265- fontSizeValues . push ( stringifyNode ( value ) )
239+ fontSizeValues . push ( stringifyNode ( node ) )
266240 break
267241 } else if ( isProperty ( 'font-family' , property ) ) {
268- fontFamilyValues . push ( stringifyNode ( value ) )
242+ fontFamilyValues . push ( stringifyNode ( node ) )
269243 break
270244 } else if ( isProperty ( 'transition' , property ) || isProperty ( 'animation' , property ) ) {
271- animations . push ( value . children )
245+ animations . push ( node . children )
272246 break
273247 } else if ( isProperty ( 'animation-duration' , property ) || isProperty ( 'transition-duration' , property ) ) {
274- durations . push ( stringifyNode ( value ) )
248+ durations . push ( stringifyNode ( node ) )
275249 break
276250 } else if ( isProperty ( 'transition-timing-function' , property ) || isProperty ( 'animation-timing-function' , property ) ) {
277- timingFunctions . push ( stringifyNode ( value ) )
251+ timingFunctions . push ( stringifyNode ( node ) )
278252 break
279253 } else if ( isProperty ( 'text-shadow' , property ) ) {
280- textShadows . push ( value )
254+ textShadows . push ( node )
281255 // no break here: potentially contains colors
282256 } else if ( isProperty ( 'box-shadow' , property ) ) {
283- boxShadows . push ( value )
257+ boxShadows . push ( node )
284258 // no break here: potentially contains colors
285259 }
286260
287- walk ( value , function ( valueNode ) {
261+ walk ( node , function ( valueNode ) {
288262 switch ( valueNode . type ) {
289263 case 'Hash' : {
290264 colors . push ( '#' + valueNode . value , property )
@@ -305,6 +279,10 @@ const analyze = (css) => {
305279 return this . skip
306280 }
307281 case 'Function' : {
282+ // Don't walk var() multiple times
283+ if ( strEquals ( 'var' , valueNode . name ) ) {
284+ return this . skip
285+ }
308286 if ( colorFunctions [ valueNode . name . toLowerCase ( ) ] ) {
309287 colors . push ( stringifyNode ( valueNode ) , property )
310288 }
@@ -313,6 +291,38 @@ const analyze = (css) => {
313291 }
314292 }
315293 } )
294+ break
295+ }
296+ case 'Declaration' : {
297+ totalDeclarations ++
298+
299+ const declaration = stringifyNode ( node )
300+ if ( declarationsCache [ declaration ] ) {
301+ declarationsCache [ declaration ] ++
302+ } else {
303+ declarationsCache [ declaration ] = 1
304+ }
305+
306+ if ( node . important ) {
307+ importantDeclarations ++
308+
309+ if ( this . atrule && endsWith ( 'keyframes' , this . atrule . name ) ) {
310+ importantsInKeyframes ++
311+ }
312+ }
313+
314+ const { property } = node
315+
316+ properties . push ( property )
317+
318+ if ( hasVendorPrefix ( property ) ) {
319+ propertyVendorPrefixes . push ( property )
320+ } else if ( isHack ( property ) ) {
321+ propertyHacks . push ( property )
322+ } else if ( isCustom ( property ) ) {
323+ customProperties . push ( property )
324+ }
325+ break
316326 }
317327 }
318328 } )
0 commit comments