Use existing prefixSelector function

This commit is contained in:
Adam Wathan 2018-09-14 16:22:49 -04:00
parent dfb8c256ab
commit e497a2b5de
2 changed files with 28 additions and 1 deletions

View File

@ -216,3 +216,29 @@ test('you can apply utility classes without using the given prefix', () => {
expect(result.warnings().length).toBe(0)
})
})
// test('you can apply utility classes without using the given prefix when using a function for the prefix', () => {
// const input = `
// .foo { @apply .tw-mt-4 .mb-4; }
// `
// const expected = `
// .foo { margin-top: 1rem; margin-bottom: 1rem; }
// `
// const config = {
// ...defaultConfig,
// options: {
// ...defaultConfig.options,
// prefix: selector => {
// return 'tw-'
// },
// },
// experiments: { shadowLookup: true },
// }
// return run(input, config, generateUtilities(config, [])).then(result => {
// expect(result.css).toEqual(expected)
// expect(result.warnings().length).toBe(0)
// })
// })

View File

@ -1,6 +1,7 @@
import _ from 'lodash'
import postcss from 'postcss'
import escapeClassName from '../util/escapeClassName'
import prefixSelector from '../util/prefixSelector'
function buildClassTable(css) {
const classTable = {}
@ -35,7 +36,7 @@ function findClass(classToApply, classTable, shadowLookup, prefix, onError) {
if (_.isEmpty(matches)) {
if (_.isEmpty(shadowLookup)) {
if (prefix) {
classToApply = '.' + prefix + classToApply.substr(1)
classToApply = prefixSelector(prefix, classToApply)
matches = _.get(classTable, classToApply, [])
if (_.isEmpty(matches)) {
if (_.isEmpty(shadowLookup)) {