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

Ignore unset values (like null or undefined) when resolving the classList for intellisense #9385

Merged
merged 2 commits into from Sep 21, 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 @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improve data type analyses for arbitrary values ([#9320](https://github.com/tailwindlabs/tailwindcss/pull/9320))
- Don't emit generated utilities with invalid uses of theme functions ([#9319](https://github.com/tailwindlabs/tailwindcss/pull/9319))
- Revert change that only listened for stdin close on TTYs ([#9331](https://github.com/tailwindlabs/tailwindcss/pull/9331))
- Ignore unset values (like `null` or `undefined`) when resolving the classList for intellisense ([#9385](https://github.com/tailwindlabs/tailwindcss/pull/9385))

## [3.1.8] - 2022-08-05

Expand Down
5 changes: 5 additions & 0 deletions src/lib/setupContextUtils.js
Expand Up @@ -838,6 +838,11 @@ function registerPlugins(plugins, context) {
let negativeClasses = []

for (let [key, value] of Object.entries(options?.values ?? {})) {
// Ignore undefined and null values
if (value == null) {
continue
}

output.push(formatClass(utilName, key))
if (options?.supportsNegativeValues && negateValue(value)) {
negativeClasses.push(formatClass(utilName, `-${key}`))
Expand Down
35 changes: 35 additions & 0 deletions tests/getClassList.test.js
Expand Up @@ -82,3 +82,38 @@ it('should not generate utilities with opacity even if safe-listed', () => {

expect(classes).not.toContain('bg-red-500/50')
})

it('should not generate utilities that are set to undefined or null to so that they are removed', () => {
let config = {
theme: {
extend: {
colors: {
red: null,
green: undefined,
blue: {
100: null,
200: undefined,
},
},
},
},
safelist: [
{
pattern: /^bg-(red|green|blue)-.*$/,
},
],
}

let context = createContext(resolveConfig(config))
let classes = context.getClassList()

expect(classes).not.toContain('bg-red-100') // Red is `null`

expect(classes).not.toContain('bg-green-100') // Green is `undefined`

expect(classes).not.toContain('bg-blue-100') // Blue.100 is `null`
expect(classes).not.toContain('bg-blue-200') // Blue.200 is `undefined`

expect(classes).toContain('bg-blue-50')
expect(classes).toContain('bg-blue-300')
})