/
githubmirror
/
tailwindcss
Обзор
Документация
Войти
/
githubmirror
/
tailwindcss
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/@tailwindcss-upgrade/src/utils/walk.ts
45 строк
1 KB
Robin Malfait
Improve performance of `@tailwindcss/postcss` and `@tailwindcss/vite` (#15226)
29 ноя 2024, 18:59
Не верифицирован
29 ноя 2024, 18:59
99b73ee
Код
Авторство
О чём код?
export const enum WalkAction { // Continue walking the tree. Default behavior. Continue, // Skip walking into the current node. Skip, // Stop walking the tree entirely. Stop, } interface Walkable<T> { each(cb: (node: T, index: number) => void): void } // Custom walk implementation where we can skip going into nodes when we don't // need to process them. export function walk<T>( rule: Walkable<T>, cb: (rule: T, idx: number, parent: Walkable<T>) => void | WalkAction, ): undefined | false { let result: undefined | false = undefined rule.each?.((node, idx) => { let action = cb(node, idx, rule) ?? WalkAction.Continue if (action === WalkAction.Stop) { result = false return result } if (action !== WalkAction.Skip) { result = walk(node as Walkable<T>, cb) return result } }) return result } // Depth first walk reversal implementation. export function walkDepth<T>(rule: Walkable<T>, cb: (rule: T) => void) { rule?.each?.((node) => { walkDepth(node as Walkable<T>, cb) cb(node) }) }