Skip to content

Commit d7d715a

Browse files
committed
fix code, test and style
1 parent 582aeec commit d7d715a

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

__tests__/applyAtRule.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,22 +195,23 @@ test('you can apply utility classes that do not actually exist as long as they w
195195

196196
test('you can apply utility classes without using the given prefix', () => {
197197
const input = `
198-
.foo { @apply .mt-4; }
198+
.foo { @apply .tw-mt-4 .mb-4; }
199199
`
200200

201201
const expected = `
202-
.prefix-foo { margin-top: 1rem; }
202+
.foo { margin-top: 1rem; margin-bottom: 1rem; }
203203
`
204204

205205
const config = {
206206
...defaultConfig,
207207
options: {
208208
...defaultConfig.options,
209-
prefix: 'prefix-',
209+
prefix: 'tw-',
210210
},
211+
experiments: { shadowLookup: true },
211212
}
212213

213-
return run(input, config).then(result => {
214+
return run(input, config, generateUtilities(config, [])).then(result => {
214215
expect(result.css).toEqual(expected)
215216
expect(result.warnings().length).toBe(0)
216217
})

src/lib/substituteClassApplyAtRules.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ function findClass(classToApply, classTable, shadowLookup, prefix, onError) {
4545

4646
return findClass(classToApply, shadowLookup, {}, '', onError)
4747
}
48+
} else {
49+
// prettier-ignore
50+
throw onError(`\`@apply\` cannot be used with \`${classToApply}\` because \`${classToApply}\` either cannot be found, or it's actual definition includes a pseudo-selector like :hover, :active, etc. If you're sure that \`${classToApply}\` exists, make sure that any \`@import\` statements are being properly processed *before* Tailwind CSS sees your CSS, as \`@apply\` can only be used for classes in the same CSS tree.`)
4851
}
49-
50-
// prettier-ignore
51-
throw onError(`\`@apply\` cannot be used with \`${classToApply}\` because \`${classToApply}\` either cannot be found, or it's actual definition includes a pseudo-selector like :hover, :active, etc. If you're sure that \`${classToApply}\` exists, make sure that any \`@import\` statements are being properly processed *before* Tailwind CSS sees your CSS, as \`@apply\` can only be used for classes in the same CSS tree.`)
52+
} else {
53+
return findClass(classToApply, shadowLookup, {}, prefix, onError)
5254
}
53-
54-
return findClass(classToApply, shadowLookup, {}, prefix, onError)
5555
}
5656

5757
if (matches.length > 1) {
@@ -94,9 +94,15 @@ export default function(config, generatedUtilities) {
9494
const decls = _(classes)
9595
.reject(cssClass => cssClass === '!important')
9696
.flatMap(cssClass => {
97-
return findClass(normalizeClassName(cssClass), classLookup, shadowLookup, config.options.prefix, message => {
98-
return atRule.error(message)
99-
})
97+
return findClass(
98+
normalizeClassName(cssClass),
99+
classLookup,
100+
shadowLookup,
101+
config.options.prefix,
102+
message => {
103+
return atRule.error(message)
104+
}
105+
)
100106
})
101107
.value()
102108

0 commit comments

Comments
 (0)