Skip to content

Commit

Permalink
switch to callback + remove countableCollection (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartveneman authored Jan 21, 2024
1 parent e5a7ce1 commit 6bfcda7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 140 deletions.
48 changes: 0 additions & 48 deletions src/countable-collection.js

This file was deleted.

67 changes: 0 additions & 67 deletions src/countable-collection.test.js

This file was deleted.

14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,13 @@ export function analyze(css, options = {}) {
} else if (isProperty('line-height', property)) {
lineHeights.p(stringifyNode(node), loc)
} else if (isProperty('transition', property) || isProperty('animation', property)) {
let [times, fns] = analyzeAnimation(children, stringifyNode)
for (let i = 0; i < times.length; i++) {
durations.p(times[i], loc)
}
for (let i = 0; i < fns.length; i++) {
timingFunctions.p(fns[i], loc)
}
analyzeAnimation(children, function (item) {
if (item.type === 'fn') {
timingFunctions.p(stringifyNode(item.value), loc)
} else if (item.type === 'duration') {
durations.p(stringifyNode(item.value), loc)
}
})
break
} else if (isProperty('animation-duration', property) || isProperty('transition-duration', property)) {
if (children && children.size > 1) {
Expand Down
4 changes: 3 additions & 1 deletion src/selectors/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-expect-error CSS Tree types are incomplete
import walk from 'css-tree/walker'
import { startsWith, strEquals } from '../string-utils.js'
import { hasVendorPrefix } from '../vendor-prefix.js'
Expand Down Expand Up @@ -28,6 +29,7 @@ function analyzeList(selectorListAst, cb) {
return childSelectors
}

/** @param {string} name */
function isPseudoFunction(name) {
return (
strEquals(name, 'not')
Expand Down Expand Up @@ -102,7 +104,7 @@ export function isPrefixed(selector) {
/**
* Get the Complexity for the AST of a Selector Node
* @param {import('css-tree').Selector} selector - AST Node for a Selector
* @return {[number, boolean]} - The numeric complexity of the Selector and whether it's prefixed or not
* @return {number} - The numeric complexity of the Selector and whether it's prefixed or not
*/
export function getComplexity(selector) {
let complexity = 0
Expand Down
21 changes: 13 additions & 8 deletions src/values/animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ const TIMING_FUNCTION_VALUES = new KeywordSet([
'steps'
])

export function analyzeAnimation(children, stringifyNode) {
export function analyzeAnimation(children, cb) {
let durationFound = false
let durations = []
let timingFunctions = []

children.forEach(child => {
let type = child.type
Expand All @@ -36,15 +34,22 @@ export function analyzeAnimation(children, stringifyNode) {
}
if (type === Dimension && durationFound === false) {
durationFound = true
return durations.push(stringifyNode(child))
return cb({
type: 'duration',
value: child,
})
}
if (type === Identifier && TIMING_KEYWORDS.has(name)) {
return timingFunctions.push(stringifyNode(child))
return cb({
type: 'fn',
value: child,
})
}
if (type === Func && TIMING_FUNCTION_VALUES.has(name)) {
return timingFunctions.push(stringifyNode(child))
return cb({
type: 'fn',
value: child,
})
}
})

return [durations, timingFunctions]
}
11 changes: 2 additions & 9 deletions src/values/vendor-prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,15 @@ export function isValuePrefixed(node) {
return false
}

let list = children.toArray()

for (let index = 0; index < list.length; index++) {
let node = list[index]
for (let node of children) {
let { type, name } = node;

if (type === Identifier && hasVendorPrefix(name)) {
return true
}

if (type === Func) {
if (hasVendorPrefix(name)) {
return true
}

if (isValuePrefixed(node)) {
if (hasVendorPrefix(name) || isValuePrefixed(node)) {
return true
}
}
Expand Down

0 comments on commit 6bfcda7

Please sign in to comment.