Skip to content

Commit 8b44717

Browse files
authored
Fix foo-[abc]/[def] not being handled correctl (#9866)
* fix `foo-[abc]/[def]` not being handled correctly This commit does a bit of cleanup, it also ensures that we lookup `[abc]/[def]` in the `values` first, and if it doesn't exist, then we start parsing all the values out. We also ensure that `abc` and `def` are parsed out correctly for the correct type instead of dropping the rule altogether because we happen to end up with an `any` rule. TODO: we should further clean the whole type system because this should only be used to figure out what type an arbitrary value is and to find the corresponding plugin and that's it. One of the fixes is doing a crazy lookup and running a generator, even though we know it is a lookup value so we should be done with all the work anyways. * update changelog
1 parent bc3d38b commit 8b44717

File tree

3 files changed

+364
-19
lines changed

3 files changed

+364
-19
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Cleanup unused `variantOrder` ([#9829](https://github.com/tailwindlabs/tailwindcss/pull/9829))
13+
- Fix `foo-[abc]/[def]` not being handled correctl ([#9866](https://github.com/tailwindlabs/tailwindcss/pull/9866))
1314

1415
### Added
1516

src/util/pluginUtils.js

+24-19
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,14 @@ export function parseColorFormat(value) {
133133
return value
134134
}
135135

136-
export function asColor(
137-
_,
138-
options = {},
139-
{ tailwindConfig = {}, utilityModifier, rawModifier } = {}
140-
) {
141-
if (options.values?.[rawModifier] !== undefined) {
142-
return parseColorFormat(options.values?.[rawModifier])
136+
export function asColor(modifier, options = {}, { tailwindConfig = {} } = {}) {
137+
if (options.values?.[modifier] !== undefined) {
138+
return parseColorFormat(options.values?.[modifier])
143139
}
144140

145141
// TODO: Hoist this up to getMatchingTypes or something
146142
// We do this here because we need the alpha value (if any)
147-
let [color, alpha] = splitUtilityModifier(rawModifier)
143+
let [color, alpha] = splitUtilityModifier(modifier)
148144

149145
if (alpha !== undefined) {
150146
let normalizedColor =
@@ -167,16 +163,16 @@ export function asColor(
167163
return withAlphaValue(normalizedColor, tailwindConfig.theme.opacity[alpha])
168164
}
169165

170-
return asValue(rawModifier, options, { rawModifier, utilityModifier, validate: validateColor })
166+
return asValue(modifier, options, { validate: validateColor })
171167
}
172168

173169
export function asLookupValue(modifier, options = {}) {
174170
return options.values?.[modifier]
175171
}
176172

177173
function guess(validate) {
178-
return (modifier, options, extras) => {
179-
return asValue(modifier, options, { ...extras, validate })
174+
return (modifier, options) => {
175+
return asValue(modifier, options, { validate })
180176
}
181177
}
182178

@@ -208,6 +204,22 @@ function splitAtFirst(input, delim) {
208204
}
209205

210206
export function coerceValue(types, modifier, options, tailwindConfig) {
207+
if (options.values && modifier in options.values) {
208+
for (let { type } of types ?? []) {
209+
let result = typeMap[type](modifier, options, {
210+
tailwindConfig,
211+
})
212+
213+
if (result === undefined) {
214+
continue
215+
}
216+
217+
return [result, type, null]
218+
}
219+
220+
return [options.values[modifier], 'lookup', null]
221+
}
222+
211223
if (isArbitraryValue(modifier)) {
212224
let arbitraryValue = modifier.slice(1, -1)
213225
let [explicitType, value] = splitAtFirst(arbitraryValue, ':')
@@ -280,17 +292,10 @@ export function* getMatchingTypes(types, rawModifier, options, tailwindConfig) {
280292
utilityModifier = utilityModifier.slice(1, -1)
281293
}
282294
}
283-
284-
let result = asValue(rawModifier, options, { rawModifier, utilityModifier, tailwindConfig })
285-
if (result !== undefined) {
286-
yield [result, 'any', null]
287-
}
288295
}
289296

290-
for (const { type } of types ?? []) {
297+
for (let { type } of types ?? []) {
291298
let result = typeMap[type](modifier, options, {
292-
rawModifier,
293-
utilityModifier,
294299
tailwindConfig,
295300
})
296301

0 commit comments

Comments
 (0)