mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
cache buildSelectorVariant
This commit is contained in:
parent
0631851b7b
commit
fab4d7b8f6
@ -1,15 +1,21 @@
|
||||
import parser from 'postcss-selector-parser'
|
||||
import tap from 'lodash/tap'
|
||||
import { useMemo } from './useMemo'
|
||||
|
||||
export default function buildSelectorVariant(selector, variantName, separator, onError = () => {}) {
|
||||
return parser(selectors => {
|
||||
tap(selectors.first.filter(({ type }) => type === 'class').pop(), classSelector => {
|
||||
if (classSelector === undefined) {
|
||||
onError('Variant cannot be generated because selector contains no classes.')
|
||||
return
|
||||
}
|
||||
const buildSelectorVariant = useMemo(
|
||||
(selector, variantName, separator, onError = () => {}) => {
|
||||
return parser(selectors => {
|
||||
tap(selectors.first.filter(({ type }) => type === 'class').pop(), classSelector => {
|
||||
if (classSelector === undefined) {
|
||||
onError('Variant cannot be generated because selector contains no classes.')
|
||||
return
|
||||
}
|
||||
|
||||
classSelector.value = `${variantName}${separator}${classSelector.value}`
|
||||
})
|
||||
}).processSync(selector)
|
||||
}
|
||||
classSelector.value = `${variantName}${separator}${classSelector.value}`
|
||||
})
|
||||
}).processSync(selector)
|
||||
},
|
||||
(selector, variantName, separator) => [selector, variantName, separator].join('||')
|
||||
)
|
||||
|
||||
export default buildSelectorVariant
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user