11import parse from 'css-tree/parser'
22import walk from 'css-tree/walker'
3- import { property as getProperty } from 'css-tree/utils'
43import { analyzeRule } from './rules/rules.js'
54import { analyzeSpecificity , compareSpecificity } from './selectors/specificity.js'
65import { colorFunctions , colorNames } from './values/colors.js'
@@ -13,6 +12,9 @@ import { analyzeAtRules } from './atrules/atrules.js'
1312import { ContextCollection } from './context-collection.js'
1413import { CountableCollection } from './countable-collection.js'
1514import { AggregateCollection } from './aggregate-collection.js'
15+ import { strEquals , startsWith , endsWith } from './string-utils.js'
16+ import { hasVendorPrefix } from './vendor-prefix.js'
17+ import { isCustom , isHack , isProperty } from './properties/property-utils.js'
1618
1719/**
1820 * Analyze CSS
@@ -133,7 +135,7 @@ const analyze = (css) => {
133135 atrules . push ( {
134136 name : node . name ,
135137 prelude : node . prelude && node . prelude . value ,
136- block : node . name === 'font-face' && node . block ,
138+ block : strEquals ( 'font-face' , node . name ) && node . block ,
137139 } )
138140 break
139141 }
@@ -153,7 +155,7 @@ const analyze = (css) => {
153155 case 'Selector' : {
154156 const selector = stringifyNode ( node )
155157
156- if ( this . atrule && this . atrule . name . endsWith ( 'keyframes' ) ) {
158+ if ( this . atrule && endsWith ( 'keyframes' , this . atrule . name ) ) {
157159 keyframeSelectors . push ( selector )
158160 return this . skip
159161 }
@@ -215,7 +217,7 @@ const analyze = (css) => {
215217 return this . skip
216218 }
217219 case 'Url' : {
218- if ( node . value . startsWith ( 'data:' ) ) {
220+ if ( startsWith ( 'data:' , node . value ) ) {
219221 embeds . push ( node . value )
220222 }
221223 break
@@ -233,7 +235,7 @@ const analyze = (css) => {
233235 if ( node . important ) {
234236 importantDeclarations ++
235237
236- if ( this . atrule && this . atrule . name . endsWith ( 'keyframes' ) ) {
238+ if ( this . atrule && endsWith ( 'keyframes' , this . atrule . name ) ) {
237239 importantsInKeyframes ++
238240 }
239241 }
@@ -243,59 +245,43 @@ const analyze = (css) => {
243245 properties . push ( property )
244246 values . push ( value )
245247
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+ }
255+
246256 // Process properties first that don't have colors,
247257 // so we can avoid further walking them;
248- // They're also typically not vendor prefixed,
249- if ( property === 'z-index' ) {
258+ if ( isProperty ( 'z-index' , property ) ) {
250259 zindex . push ( value )
251260 return this . skip
252- }
253- if ( property === 'font' ) {
261+ } else if ( isProperty ( 'font' , property ) ) {
254262 fontValues . push ( value )
255263 break
256- }
257- if ( property === 'font-size' ) {
264+ } else if ( isProperty ( 'font-size' , property ) ) {
258265 fontSizeValues . push ( stringifyNode ( value ) )
259266 break
260- }
261- if ( property === 'font-family' ) {
267+ } else if ( isProperty ( 'font-family' , property ) ) {
262268 fontFamilyValues . push ( stringifyNode ( value ) )
263269 break
264- }
265-
266- const {
267- vendor : isVendor ,
268- hack : isHack ,
269- custom : isCustom ,
270- basename,
271- } = getProperty ( property )
272-
273- if ( isVendor ) {
274- propertyVendorPrefixes . push ( property )
275- }
276- if ( isHack ) {
277- propertyHacks . push ( property )
278- }
279- if ( isCustom ) {
280- customProperties . push ( property )
281- }
282-
283- if ( basename === 'transition' || basename === 'animation' ) {
270+ } else if ( isProperty ( 'transition' , property ) || isProperty ( 'animation' , property ) ) {
284271 animations . push ( value . children )
285272 break
286- } else if ( basename === 'animation-duration' || basename === 'transition-duration' ) {
273+ } else if ( isProperty ( 'animation-duration' , property ) || isProperty ( 'transition-duration' , property ) ) {
287274 durations . push ( stringifyNode ( value ) )
288275 break
289- } else if ( basename === 'transition-timing-function' || basename === 'animation-timing-function' ) {
276+ } else if ( isProperty ( 'transition-timing-function' , property ) || isProperty ( 'animation-timing-function' , property ) ) {
290277 timingFunctions . push ( stringifyNode ( value ) )
291278 break
292- }
293-
294- // These properties potentially contain colors
295- if ( basename === 'text-shadow' ) {
279+ } else if ( isProperty ( 'text-shadow' , property ) ) {
296280 textShadows . push ( value )
297- } else if ( basename === 'box-shadow' ) {
281+ // no break here: potentially contains colors
282+ } else if ( isProperty ( 'box-shadow' , property ) ) {
298283 boxShadows . push ( value )
284+ // no break here: potentially contains colors
299285 }
300286
301287 walk ( value , function ( valueNode ) {
0 commit comments