Skip to content

Commit 6bfcda7

Browse files
authored
switch to callback + remove countableCollection (#382)
1 parent e5a7ce1 commit 6bfcda7

File tree

6 files changed

+25
-140
lines changed

6 files changed

+25
-140
lines changed

src/countable-collection.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/countable-collection.test.js

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,13 @@ export function analyze(css, options = {}) {
476476
} else if (isProperty('line-height', property)) {
477477
lineHeights.p(stringifyNode(node), loc)
478478
} else if (isProperty('transition', property) || isProperty('animation', property)) {
479-
let [times, fns] = analyzeAnimation(children, stringifyNode)
480-
for (let i = 0; i < times.length; i++) {
481-
durations.p(times[i], loc)
482-
}
483-
for (let i = 0; i < fns.length; i++) {
484-
timingFunctions.p(fns[i], loc)
485-
}
479+
analyzeAnimation(children, function (item) {
480+
if (item.type === 'fn') {
481+
timingFunctions.p(stringifyNode(item.value), loc)
482+
} else if (item.type === 'duration') {
483+
durations.p(stringifyNode(item.value), loc)
484+
}
485+
})
486486
break
487487
} else if (isProperty('animation-duration', property) || isProperty('transition-duration', property)) {
488488
if (children && children.size > 1) {

src/selectors/utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-expect-error CSS Tree types are incomplete
12
import walk from 'css-tree/walker'
23
import { startsWith, strEquals } from '../string-utils.js'
34
import { hasVendorPrefix } from '../vendor-prefix.js'
@@ -28,6 +29,7 @@ function analyzeList(selectorListAst, cb) {
2829
return childSelectors
2930
}
3031

32+
/** @param {string} name */
3133
function isPseudoFunction(name) {
3234
return (
3335
strEquals(name, 'not')
@@ -102,7 +104,7 @@ export function isPrefixed(selector) {
102104
/**
103105
* Get the Complexity for the AST of a Selector Node
104106
* @param {import('css-tree').Selector} selector - AST Node for a Selector
105-
* @return {[number, boolean]} - The numeric complexity of the Selector and whether it's prefixed or not
107+
* @return {number} - The numeric complexity of the Selector and whether it's prefixed or not
106108
*/
107109
export function getComplexity(selector) {
108110
let complexity = 0

src/values/animations.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ const TIMING_FUNCTION_VALUES = new KeywordSet([
2121
'steps'
2222
])
2323

24-
export function analyzeAnimation(children, stringifyNode) {
24+
export function analyzeAnimation(children, cb) {
2525
let durationFound = false
26-
let durations = []
27-
let timingFunctions = []
2826

2927
children.forEach(child => {
3028
let type = child.type
@@ -36,15 +34,22 @@ export function analyzeAnimation(children, stringifyNode) {
3634
}
3735
if (type === Dimension && durationFound === false) {
3836
durationFound = true
39-
return durations.push(stringifyNode(child))
37+
return cb({
38+
type: 'duration',
39+
value: child,
40+
})
4041
}
4142
if (type === Identifier && TIMING_KEYWORDS.has(name)) {
42-
return timingFunctions.push(stringifyNode(child))
43+
return cb({
44+
type: 'fn',
45+
value: child,
46+
})
4347
}
4448
if (type === Func && TIMING_FUNCTION_VALUES.has(name)) {
45-
return timingFunctions.push(stringifyNode(child))
49+
return cb({
50+
type: 'fn',
51+
value: child,
52+
})
4653
}
4754
})
48-
49-
return [durations, timingFunctions]
5055
}

src/values/vendor-prefix.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,15 @@ export function isValuePrefixed(node) {
1111
return false
1212
}
1313

14-
let list = children.toArray()
15-
16-
for (let index = 0; index < list.length; index++) {
17-
let node = list[index]
14+
for (let node of children) {
1815
let { type, name } = node;
1916

2017
if (type === Identifier && hasVendorPrefix(name)) {
2118
return true
2219
}
2320

2421
if (type === Func) {
25-
if (hasVendorPrefix(name)) {
26-
return true
27-
}
28-
29-
if (isValuePrefixed(node)) {
22+
if (hasVendorPrefix(name) || isValuePrefixed(node)) {
3023
return true
3124
}
3225
}

0 commit comments

Comments
 (0)