re-use classNameParser
We were re-creating the classNameParser inside the loop. Since that code is all pretty pure we can hoist it so that we don't have to recreate that parser all the time.
This commit is contained in:
parent
8c7fb84e58
commit
aa7ae6af37
1 changed files with 5 additions and 3 deletions
|
|
@ -2,6 +2,10 @@ import _ from 'lodash'
|
|||
import postcss from 'postcss'
|
||||
import selectorParser from 'postcss-selector-parser'
|
||||
|
||||
const classNameParser = selectorParser(selectors => {
|
||||
return selectors.first.filter(({ type }) => type === 'class').pop().value
|
||||
})
|
||||
|
||||
export default function generateVariantFunction(generator) {
|
||||
return (container, config) => {
|
||||
const cloned = postcss.root({ nodes: container.clone().nodes })
|
||||
|
|
@ -18,9 +22,7 @@ export default function generateVariantFunction(generator) {
|
|||
}
|
||||
|
||||
rule.selectors = rule.selectors.map(selector => {
|
||||
const className = selectorParser(selectors => {
|
||||
return selectors.first.filter(({ type }) => type === 'class').pop().value
|
||||
}).transformSync(selector)
|
||||
const className = classNameParser.transformSync(selector)
|
||||
|
||||
return modifierFunction({
|
||||
className,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue