Skip to content

Commit e625252

Browse files
authored
Ignore unset values (like null or undefined) when resolving the classList for intellisense (#9385)
* ignored `undefined` and `null` value values for intellisense We are not completely ignoring "all" falsey values, because then we would get rid of `0` values (e.g.: `p-0`) which is not what we want. * update changelog
1 parent 063ca64 commit e625252

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3434
- Improve data type analyses for arbitrary values ([#9320](https://github.com/tailwindlabs/tailwindcss/pull/9320))
3535
- Don't emit generated utilities with invalid uses of theme functions ([#9319](https://github.com/tailwindlabs/tailwindcss/pull/9319))
3636
- Revert change that only listened for stdin close on TTYs ([#9331](https://github.com/tailwindlabs/tailwindcss/pull/9331))
37+
- Ignore unset values (like `null` or `undefined`) when resolving the classList for intellisense ([#9385](https://github.com/tailwindlabs/tailwindcss/pull/9385))
3738

3839
## [3.1.8] - 2022-08-05
3940

src/lib/setupContextUtils.js

+5
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,11 @@ function registerPlugins(plugins, context) {
838838
let negativeClasses = []
839839

840840
for (let [key, value] of Object.entries(options?.values ?? {})) {
841+
// Ignore undefined and null values
842+
if (value == null) {
843+
continue
844+
}
845+
841846
output.push(formatClass(utilName, key))
842847
if (options?.supportsNegativeValues && negateValue(value)) {
843848
negativeClasses.push(formatClass(utilName, `-${key}`))

tests/getClassList.test.js

+35
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,38 @@ it('should not generate utilities with opacity even if safe-listed', () => {
8282

8383
expect(classes).not.toContain('bg-red-500/50')
8484
})
85+
86+
it('should not generate utilities that are set to undefined or null to so that they are removed', () => {
87+
let config = {
88+
theme: {
89+
extend: {
90+
colors: {
91+
red: null,
92+
green: undefined,
93+
blue: {
94+
100: null,
95+
200: undefined,
96+
},
97+
},
98+
},
99+
},
100+
safelist: [
101+
{
102+
pattern: /^bg-(red|green|blue)-.*$/,
103+
},
104+
],
105+
}
106+
107+
let context = createContext(resolveConfig(config))
108+
let classes = context.getClassList()
109+
110+
expect(classes).not.toContain('bg-red-100') // Red is `null`
111+
112+
expect(classes).not.toContain('bg-green-100') // Green is `undefined`
113+
114+
expect(classes).not.toContain('bg-blue-100') // Blue.100 is `null`
115+
expect(classes).not.toContain('bg-blue-200') // Blue.200 is `undefined`
116+
117+
expect(classes).toContain('bg-blue-50')
118+
expect(classes).toContain('bg-blue-300')
119+
})

0 commit comments

Comments
 (0)