Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Commit 445b30b

Browse files
committed
Clean up some gruesomeness
1 parent 4a03bca commit 445b30b

File tree

1 file changed

+13
-32
lines changed

1 file changed

+13
-32
lines changed

src/lib/setupContext.js

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,14 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
349349
return prefixSelector(tailwindConfig.prefix, selector)
350350
}
351351

352+
function prefixIdentifier(identifier, options) {
353+
if (identifier === '*') {
354+
return '*'
355+
}
356+
357+
return options.respectPrefix ? context.tailwindConfig.prefix + identifier : identifier
358+
}
359+
352360
return {
353361
addVariant(variantName, applyThisVariant, options = {}) {
354362
insertInto(variantList, variantName, options)
@@ -379,13 +387,7 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
379387
},
380388
addBase(base) {
381389
for (let [identifier, rule] of withIdentifiers(base)) {
382-
let prefixedIdentifier =
383-
identifier === '*'
384-
? '*'
385-
: options.respectPrefix
386-
? context.tailwindConfig.prefix + identifier
387-
: identifier
388-
390+
let prefixedIdentifier = prefixIdentifier(identifier, {})
389391
let offset = offsets.base++
390392

391393
if (!context.candidateRuleMap.has(prefixedIdentifier)) {
@@ -412,12 +414,7 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
412414
)
413415

414416
for (let [identifier, rule] of withIdentifiers(components)) {
415-
let prefixedIdentifier =
416-
identifier === '*'
417-
? '*'
418-
: options.respectPrefix
419-
? context.tailwindConfig.prefix + identifier
420-
: identifier
417+
let prefixedIdentifier = prefixIdentifier(identifier, options)
421418
let offset = offsets.components++
422419

423420
if (!context.candidateRuleMap.has(prefixedIdentifier)) {
@@ -444,12 +441,7 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
444441
)
445442

446443
for (let [identifier, rule] of withIdentifiers(utilities)) {
447-
let prefixedIdentifier =
448-
identifier === '*'
449-
? '*'
450-
: options.respectPrefix
451-
? context.tailwindConfig.prefix + identifier
452-
: identifier
444+
let prefixedIdentifier = prefixIdentifier(identifier, options)
453445
let offset = offsets.utilities++
454446

455447
if (!context.candidateRuleMap.has(prefixedIdentifier)) {
@@ -465,12 +457,7 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
465457
let offset = offsets.base++
466458

467459
for (let identifier in base) {
468-
let prefixedIdentifier =
469-
identifier === '*'
470-
? '*'
471-
: options.respectPrefix
472-
? context.tailwindConfig.prefix + identifier
473-
: identifier
460+
let prefixedIdentifier = prefixIdentifier(identifier, options)
474461
let value = [].concat(base[identifier])
475462

476463
let withOffsets = value.map((rule) => [{ sort: offset, layer: 'base' }, rule])
@@ -495,13 +482,7 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
495482
let offset = offsets.utilities++
496483

497484
for (let identifier in utilities) {
498-
let prefixedIdentifier =
499-
identifier === '*'
500-
? '*'
501-
: options.respectPrefix
502-
? context.tailwindConfig.prefix + identifier
503-
: identifier
504-
485+
let prefixedIdentifier = prefixIdentifier(identifier, options)
505486
let value = [].concat(utilities[identifier])
506487

507488
let withOffsets = value.map((rule) => [{ sort: offset, layer: 'utilities', options }, rule])

0 commit comments

Comments
 (0)