Remove blocklisted classes from autocomplete (#10844)

* Remove blocklisted classes from autocomplete

* Update changelog

* Don't unnecessary loop over classes

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
This commit is contained in:
Jordan Pittman 2023-03-23 15:03:56 -04:00 • committed by GitHub
parent eadd6e5de9
commit f1473f53bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View file

@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Disallow multiple selectors in arbitrary variants ([#10655](https://github.com/tailwindlabs/tailwindcss/pull/10655))
- Sort class lists deterministically for Prettier plugin ([#10672](https://github.com/tailwindlabs/tailwindcss/pull/10672))
- Ensure CLI builds have a non-zero exit code on failure ([#10703](https://github.com/tailwindlabs/tailwindcss/pull/10703))
- Remove blocklisted classes from autocomplete ([#10844](https://github.com/tailwindlabs/tailwindcss/pull/10844))
### Changed

View file

@ -1007,6 +1007,11 @@ function registerPlugins(plugins, context) {
}
}
// Exclude utilities that are known non-classes (e.g. from the blocklist)
if (context.notClassCache.size > 0) {
output = output.filter((cls) => !context.notClassCache.has(cls))
}
return output
}

View file

@ -191,6 +191,18 @@ crosscheck(() => {
expect(classes).not.toContain('bg-red-500/50')
})
it('should not generate utilities that are present in the blocklist', () => {
let config = {
blocklist: ['font-bold'],
}
let context = createContext(resolveConfig(config))
let classes = context.getClassList()
expect(classes).toContain('font-normal')
expect(classes).not.toContain('font-bold')
})
it('should not generate utilities that are set to undefined or null to so that they are removed', () => {
let config = {
theme: {