Skip to content

Commit 42296f2

Browse files
committed
Refactor
1 parent 623718e commit 42296f2

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

src/lib/setupContextUtils.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,30 @@ function withIdentifiers(styles) {
170170
})
171171
}
172172

173+
export function parseVariant(variant) {
174+
variant = variant
175+
.replace(/\n+/g, '')
176+
.replace(/\s{1,}/g, ' ')
177+
.trim()
178+
179+
let fns = parseVariantFormatString(variant)
180+
.map((str) => {
181+
if (!str.startsWith('@')) {
182+
return ({ format }) => format(str)
183+
}
184+
185+
let [, name, params] = /@(.*?) (.*)/g.exec(str)
186+
return ({ wrap }) => wrap(postcss.atRule({ name, params }))
187+
})
188+
.reverse()
189+
190+
return (api) => {
191+
for (let fn of fns) {
192+
fn(api)
193+
}
194+
}
195+
}
196+
173197
function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offsets, classList }) {
174198
function getConfigValue(path, defaultValue) {
175199
return path ? dlv(tailwindConfig, path, defaultValue) : tailwindConfig
@@ -201,27 +225,7 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
201225
}
202226
}
203227

204-
variantFunction = variantFunction
205-
.replace(/\n+/g, '')
206-
.replace(/\s{1,}/g, ' ')
207-
.trim()
208-
209-
let fns = parseVariantFormatString(variantFunction)
210-
.map((str) => {
211-
if (!str.startsWith('@')) {
212-
return ({ format }) => format(str)
213-
}
214-
215-
let [, name, params] = /@(.*?) (.*)/g.exec(str)
216-
return ({ wrap }) => wrap(postcss.atRule({ name, params }))
217-
})
218-
.reverse()
219-
220-
return (api) => {
221-
for (let fn of fns) {
222-
fn(api)
223-
}
224-
}
228+
return parseVariant(variantFunction)
225229
})
226230

227231
insertInto(variantList, variantName, options)

0 commit comments

Comments
 (0)