mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
Escape class names provided in @apply
Without this, can't mixin stuff like .w-1/4.
This commit is contained in:
parent
082fd3a389
commit
9a880d43ea
@ -1,13 +1,27 @@
|
||||
import postcss from 'postcss'
|
||||
import _ from 'lodash'
|
||||
import findMixin from '../util/findMixin'
|
||||
import escapeClassName from '../util/escapeClassName'
|
||||
|
||||
function normalizeClassNames(classNames) {
|
||||
return classNames.map((className) => {
|
||||
return `.${escapeClassName(_.trimStart(className, '.'))}`
|
||||
})
|
||||
}
|
||||
|
||||
export default postcss.plugin('tailwind-apply', function(css) {
|
||||
return function(css) {
|
||||
css.walkRules(function(rule) {
|
||||
rule.walkAtRules('apply', atRule => {
|
||||
const mixins = postcss.list.space(atRule.params)
|
||||
const mixins = normalizeClassNames(postcss.list.space(atRule.params))
|
||||
|
||||
/*
|
||||
* Don't wreck CSSNext-style @apply rules:
|
||||
* http://cssnext.io/features/#custom-properties-set-apply
|
||||
*
|
||||
* These are deprecated in CSSNext but still playing it safe for now.
|
||||
* We might consider renaming this at-rule.
|
||||
*/
|
||||
const [customProperties, classes] = _.partition(mixins, mixin => {
|
||||
return _.startsWith(mixin, '--')
|
||||
})
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
import _ from 'lodash'
|
||||
import postcss from 'postcss'
|
||||
|
||||
function escapeSelector(selector) {
|
||||
return selector.replace(/([^A-Za-z0-9\-])/g, "\\$1")
|
||||
}
|
||||
import escapeClassName from './escapeClassName'
|
||||
|
||||
export default function(className, properties) {
|
||||
const decls = _.map(properties, (value, property) => {
|
||||
@ -14,6 +11,6 @@ export default function(className, properties) {
|
||||
})
|
||||
|
||||
return postcss.rule({
|
||||
selector: `.${escapeSelector(className)}`,
|
||||
selector: `.${escapeClassName(className)}`,
|
||||
}).append(decls)
|
||||
}
|
||||
|
||||
3
src/util/escapeClassName.js
Normal file
3
src/util/escapeClassName.js
Normal file
@ -0,0 +1,3 @@
|
||||
export default function escapeClassName(className) {
|
||||
return className.replace(/([^A-Za-z0-9\-])/g, "\\$1")
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user