@@ -115,7 +115,7 @@ const analyze = (css) => {
115115 isKeyframeSelector : this . atrule && this . atrule . name . endsWith ( 'keyframes' )
116116 } )
117117
118- // Avoid further walking of selectors to not mess with
118+ // Avoid deeper walking of selectors to not mess with
119119 // our specificity calculations in case of a selector
120120 // with :where() or :is() that contain SelectorLists
121121 // as children
@@ -193,34 +193,32 @@ const analyze = (css) => {
193193 }
194194 }
195195
196- walk ( value , {
197- enter : function ( valueNode ) {
198- switch ( valueNode . type ) {
199- case 'Hash' : {
200- colors . push ( stringifyNode ( valueNode ) , property )
196+ walk ( value , function ( valueNode ) {
197+ switch ( valueNode . type ) {
198+ case 'Hash' : {
199+ colors . push ( stringifyNode ( valueNode ) , property )
201200
201+ return this . skip
202+ }
203+ case 'Identifier' : {
204+ const { name } = valueNode
205+ // Bail out if it can't be a color name
206+ // 20 === 'lightgoldenrodyellow'.length
207+ // 3 === 'red'.length
208+ if ( name . length > 20 || name . length < 3 ) {
202209 return this . skip
203210 }
204- case 'Identifier' : {
205- const { name } = valueNode
206- // Bail out if it can't be a color name
207- // 20 === 'lightgoldenrodyellow'.length
208- // 3 === 'red'.length
209- if ( name . length > 20 || name . length < 3 ) {
210- return this . skip
211- }
212- if ( colorNames [ name . toLowerCase ( ) ] ) {
213- colors . push ( stringifyNode ( valueNode ) , property )
214- }
215- return this . skip
211+ if ( colorNames [ name . toLowerCase ( ) ] ) {
212+ colors . push ( stringifyNode ( valueNode ) , property )
216213 }
217- case 'Function' : {
218- if ( colorFunctions [ valueNode . name . toLowerCase ( ) ] ) {
219- colors . push ( stringifyNode ( valueNode ) , property )
220- }
221- // No this.skip here intentionally,
222- // otherwise we'll miss colors in linear-gradient() etc.
214+ return this . skip
215+ }
216+ case 'Function' : {
217+ if ( colorFunctions [ valueNode . name . toLowerCase ( ) ] ) {
218+ colors . push ( stringifyNode ( valueNode ) , property )
223219 }
220+ // No this.skip here intentionally,
221+ // otherwise we'll miss colors in linear-gradient() etc.
224222 }
225223 }
226224 } )
0 commit comments