Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to callback + remove countableCollection #382

Merged
merged 1 commit into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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