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

Remove prefix as a function #5829

Merged
merged 4 commits into from
Oct 19, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

### Added

Expand Down
3 changes: 2 additions & 1 deletion src/lib/generateRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ function* resolveMatchedPlugins(classCandidate, context) {
let candidatePrefix = classCandidate
let negative = false

const twConfigPrefix = context.tailwindConfig.prefix || ''
const twConfigPrefix = context.tailwindConfig.prefix

const twConfigPrefixLen = twConfigPrefix.length
if (candidatePrefix[twConfigPrefixLen] === '-') {
negative = true
Expand Down
4 changes: 0 additions & 4 deletions src/lib/setupContextUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
return identifier
}

if (typeof context.tailwindConfig.prefix === 'function') {
return prefixSelector(context.tailwindConfig.prefix, `.${identifier}`).substr(1)
}

return context.tailwindConfig.prefix + identifier
}

Expand Down
12 changes: 12 additions & 0 deletions src/util/normalizeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ export function normalizeConfig(config) {
return []
})()

// Normalize prefix option
if (typeof config.prefix === 'function') {
log.warn('prefix-function', [
'As of Tailwind CSS v3.0, `prefix` cannot be a function.',
'Update `prefix` in your configuration to be a string to eliminate this warning.',
// TODO: Add https://tw.wtf/prefix-function
])
config.prefix = ''
} else {
config.prefix = config.prefix ?? ''
}

// Normalize the `content`
config.content = {
files: (() => {
Expand Down
5 changes: 1 addition & 4 deletions src/util/prefixSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ import parser from 'postcss-selector-parser'
import { tap } from './tap'

export default function (prefix, selector) {
const getPrefix =
typeof prefix === 'function' ? prefix : () => (prefix === undefined ? '' : prefix)

return parser((selectors) => {
selectors.walkClasses((classSelector) => {
tap(classSelector.value, (baseClass) => {
classSelector.value = `${getPrefix('.' + baseClass)}${baseClass}`
classSelector.value = `${prefix}${baseClass}`
})
})
}).processSync(selector)
Expand Down
9 changes: 0 additions & 9 deletions tests/prefix.fn.test.css

This file was deleted.

3 changes: 0 additions & 3 deletions tests/prefix.fn.test.html

This file was deleted.

25 changes: 0 additions & 25 deletions tests/prefix.fn.test.js

This file was deleted.

9 changes: 0 additions & 9 deletions tests/prefixSelector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ test('it prefixes classes with the provided prefix', () => {
expect(prefix('tw-', '.foo')).toEqual('.tw-foo')
})

test('it handles a function as the prefix', () => {
const prefixFunc = (selector) => {
return selector === '.foo' ? 'tw-' : ''
}

expect(prefix(prefixFunc, '.foo')).toEqual('.tw-foo')
expect(prefix(prefixFunc, '.bar')).toEqual('.bar')
})

test('it properly prefixes selectors with non-standard characters', () => {
expect(prefix('tw-', '.hello\\:world')).toEqual('.tw-hello\\:world')
expect(prefix('tw-', '.foo\\/bar')).toEqual('.tw-foo\\/bar')
Expand Down