Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix foo-[abc]/[def] not being handled correctly #9866

Merged
merged 2 commits into from Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

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

### Added

Expand Down
43 changes: 24 additions & 19 deletions src/util/pluginUtils.js
Expand Up @@ -133,18 +133,14 @@ export function parseColorFormat(value) {
return value
}

export function asColor(
_,
options = {},
{ tailwindConfig = {}, utilityModifier, rawModifier } = {}
) {
if (options.values?.[rawModifier] !== undefined) {
return parseColorFormat(options.values?.[rawModifier])
export function asColor(modifier, options = {}, { tailwindConfig = {} } = {}) {
if (options.values?.[modifier] !== undefined) {
return parseColorFormat(options.values?.[modifier])
}

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

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

return asValue(rawModifier, options, { rawModifier, utilityModifier, validate: validateColor })
return asValue(modifier, options, { validate: validateColor })
}

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

function guess(validate) {
return (modifier, options, extras) => {
return asValue(modifier, options, { ...extras, validate })
return (modifier, options) => {
return asValue(modifier, options, { validate })
}
}

Expand Down Expand Up @@ -208,6 +204,22 @@ function splitAtFirst(input, delim) {
}

export function coerceValue(types, modifier, options, tailwindConfig) {
if (options.values && modifier in options.values) {
for (let { type } of types ?? []) {
let result = typeMap[type](modifier, options, {
tailwindConfig,
})

if (result === undefined) {
continue
}

return [result, type, null]
}

return [options.values[modifier], 'lookup', null]
}

if (isArbitraryValue(modifier)) {
let arbitraryValue = modifier.slice(1, -1)
let [explicitType, value] = splitAtFirst(arbitraryValue, ':')
Expand Down Expand Up @@ -280,17 +292,10 @@ export function* getMatchingTypes(types, rawModifier, options, tailwindConfig) {
utilityModifier = utilityModifier.slice(1, -1)
}
}

let result = asValue(rawModifier, options, { rawModifier, utilityModifier, tailwindConfig })
if (result !== undefined) {
yield [result, 'any', null]
}
}

for (const { type } of types ?? []) {
for (let { type } of types ?? []) {
let result = typeMap[type](modifier, options, {
rawModifier,
utilityModifier,
tailwindConfig,
})

Expand Down