Skip to content

Commit 1a564fa

Browse files
committed
Co-locate addVariant and matchVariant
1 parent 23d3a31 commit 1a564fa

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

src/lib/setupContextUtils.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -222,40 +222,6 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
222222
}
223223

224224
let api = {
225-
addVariant(variantName, variantFunctions, options = {}) {
226-
variantFunctions = [].concat(variantFunctions).map((variantFunction) => {
227-
if (typeof variantFunction !== 'string') {
228-
// Safelist public API functions
229-
return ({ args, modifySelectors, container, separator, wrap, format }) => {
230-
let result = variantFunction(
231-
Object.assign(
232-
{ modifySelectors, container, separator },
233-
variantFunction[MATCH_VARIANT] && { args, wrap, format }
234-
)
235-
)
236-
237-
if (typeof result === 'string' && !isValidVariantFormatString(result)) {
238-
throw new Error(
239-
`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`
240-
)
241-
}
242-
243-
return result
244-
}
245-
}
246-
247-
if (!isValidVariantFormatString(variantFunction)) {
248-
throw new Error(
249-
`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`
250-
)
251-
}
252-
253-
return parseVariant(variantFunction)
254-
})
255-
256-
insertInto(variantList, variantName, options)
257-
variantMap.set(variantName, variantFunctions)
258-
},
259225
postcss,
260226
prefix: applyConfiguredPrefix,
261227
e: escapeClassName,
@@ -469,6 +435,40 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
469435
context.candidateRuleMap.get(prefixedIdentifier).push(withOffsets)
470436
}
471437
},
438+
addVariant(variantName, variantFunctions, options = {}) {
439+
variantFunctions = [].concat(variantFunctions).map((variantFunction) => {
440+
if (typeof variantFunction !== 'string') {
441+
// Safelist public API functions
442+
return ({ args, modifySelectors, container, separator, wrap, format }) => {
443+
let result = variantFunction(
444+
Object.assign(
445+
{ modifySelectors, container, separator },
446+
variantFunction[MATCH_VARIANT] && { args, wrap, format }
447+
)
448+
)
449+
450+
if (typeof result === 'string' && !isValidVariantFormatString(result)) {
451+
throw new Error(
452+
`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`
453+
)
454+
}
455+
456+
return result
457+
}
458+
}
459+
460+
if (!isValidVariantFormatString(variantFunction)) {
461+
throw new Error(
462+
`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`
463+
)
464+
}
465+
466+
return parseVariant(variantFunction)
467+
})
468+
469+
insertInto(variantList, variantName, options)
470+
variantMap.set(variantName, variantFunctions)
471+
},
472472
matchVariant: function (variants, options) {
473473
for (let variant in variants) {
474474
for (let [k, v] of Object.entries(options?.values ?? {})) {

0 commit comments

Comments
 (0)