Skip to content

Commit 0c2f1a6

Browse files
authored
Remove prefix as a function (#5829)
* mark `prefix` as a function as a breaking change * remove `prefix` as a function related code * remove `prefix` as a function related tests * update changelog
1 parent 36c880a commit 0c2f1a6

File tree

9 files changed

+16
-55
lines changed

9 files changed

+16
-55
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Don't use pointer cursor on disabled buttons by default ([#5772](https://github.com/tailwindlabs/tailwindcss/pull/5772))
1313
- Set default content value in preflight instead of within each before/after utility ([#5820](https://github.com/tailwindlabs/tailwindcss/pull/5820))
14+
- Remove `prefix` as a function ([#5829](https://github.com/tailwindlabs/tailwindcss/pull/5829))
1415

1516
### Added
1617

src/lib/generateRules.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ function* resolveMatchedPlugins(classCandidate, context) {
253253
let candidatePrefix = classCandidate
254254
let negative = false
255255

256-
const twConfigPrefix = context.tailwindConfig.prefix || ''
256+
const twConfigPrefix = context.tailwindConfig.prefix
257+
257258
const twConfigPrefixLen = twConfigPrefix.length
258259
if (candidatePrefix[twConfigPrefixLen] === '-') {
259260
negative = true

src/lib/setupContextUtils.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,6 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
206206
return identifier
207207
}
208208

209-
if (typeof context.tailwindConfig.prefix === 'function') {
210-
return prefixSelector(context.tailwindConfig.prefix, `.${identifier}`).substr(1)
211-
}
212-
213209
return context.tailwindConfig.prefix + identifier
214210
}
215211

src/util/normalizeConfig.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ export function normalizeConfig(config) {
140140
return []
141141
})()
142142

143+
// Normalize prefix option
144+
if (typeof config.prefix === 'function') {
145+
log.warn('prefix-function', [
146+
'As of Tailwind CSS v3.0, `prefix` cannot be a function.',
147+
'Update `prefix` in your configuration to be a string to eliminate this warning.',
148+
// TODO: Add https://tw.wtf/prefix-function
149+
])
150+
config.prefix = ''
151+
} else {
152+
config.prefix = config.prefix ?? ''
153+
}
154+
143155
// Normalize the `content`
144156
config.content = {
145157
files: (() => {

src/util/prefixSelector.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ import parser from 'postcss-selector-parser'
22
import { tap } from './tap'
33

44
export default function (prefix, selector) {
5-
const getPrefix =
6-
typeof prefix === 'function' ? prefix : () => (prefix === undefined ? '' : prefix)
7-
85
return parser((selectors) => {
96
selectors.walkClasses((classSelector) => {
107
tap(classSelector.value, (baseClass) => {
11-
classSelector.value = `${getPrefix('.' + baseClass)}${baseClass}`
8+
classSelector.value = `${prefix}${baseClass}`
129
})
1310
})
1411
}).processSync(selector)

tests/prefix.fn.test.css

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/prefix.fn.test.html

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/prefix.fn.test.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/prefixSelector.test.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ test('it prefixes classes with the provided prefix', () => {
44
expect(prefix('tw-', '.foo')).toEqual('.tw-foo')
55
})
66

7-
test('it handles a function as the prefix', () => {
8-
const prefixFunc = (selector) => {
9-
return selector === '.foo' ? 'tw-' : ''
10-
}
11-
12-
expect(prefix(prefixFunc, '.foo')).toEqual('.tw-foo')
13-
expect(prefix(prefixFunc, '.bar')).toEqual('.bar')
14-
})
15-
167
test('it properly prefixes selectors with non-standard characters', () => {
178
expect(prefix('tw-', '.hello\\:world')).toEqual('.tw-hello\\:world')
189
expect(prefix('tw-', '.foo\\/bar')).toEqual('.tw-foo\\/bar')

0 commit comments

Comments
 (0)