Skip to content

Commit

Permalink
feat: support css-loader @value
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyOGo committed May 29, 2020
1 parent 8931d2f commit a466b38
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,18 @@ const ruleFunction = (properties, options, context = {}) => (root, result) => {
const autoFixFuncNormalized = getAutoFixFunc(autoFixFunc)
const reKeywords = ignoreKeywords ? {} : null
const reValues = ignoreValues ? {} : null
const cssLoaderValues = {}
let cssLoaderValues = []

root.walkAtRules('value', (rule) => {
const { params } = rule
const name = params.split(':')[0].trim()
if (ignoreVariables) {
root.walkAtRules('value', (rule) => {
const { params } = rule
const name = params.split(':')[0].trim()

cssLoaderValues[name] = true
})
cssLoaderValues.push(name)
})

cssLoaderValues = new RegExp(`^-?(:?${cssLoaderValues.join('|')})$`)
}

// loop through all properties
properties.forEach((property) => {
Expand Down Expand Up @@ -184,7 +188,7 @@ const ruleFunction = (properties, options, context = {}) => (root, result) => {

// test variable
if (ignoreVariables) {
validVar = reVar.test(value) || cssLoaderValues[value]
validVar = reVar.test(value) || cssLoaderValues.test(value)
}

// test function
Expand Down

0 comments on commit a466b38

Please sign in to comment.