File tree Expand file tree Collapse file tree 2 files changed +67
-8
lines changed Expand file tree Collapse file tree 2 files changed +67
-8
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,11 @@ import { resolveMatches } from './generateRules'
3
3
import bigSign from '../util/bigSign'
4
4
import escapeClassName from '../util/escapeClassName'
5
5
6
+ function prefix ( context , selector ) {
7
+ let prefix = context . tailwindConfig . prefix
8
+ return typeof prefix === 'function' ? prefix ( selector ) : prefix + selector
9
+ }
10
+
6
11
function buildApplyCache ( applyCandidates , context ) {
7
12
for ( let candidate of applyCandidates ) {
8
13
if ( context . notClassCache . has ( candidate ) || context . applyClassCache . has ( candidate ) ) {
@@ -170,6 +175,11 @@ function processApply(root, context) {
170
175
171
176
for ( let applyCandidate of applyCandidates ) {
172
177
if ( ! applyClassCache . has ( applyCandidate ) ) {
178
+ if ( applyCandidate === prefix ( context , 'group' ) ) {
179
+ // TODO: Link to specific documentation page with error code.
180
+ throw apply . error ( `@apply should not be used with the '${ applyCandidate } ' utility` )
181
+ }
182
+
173
183
throw apply . error (
174
184
`The \`${ applyCandidate } \` class does not exist. If \`${ applyCandidate } \` is a custom class, make sure it is defined within a \`@layer\` directive.`
175
185
)
Original file line number Diff line number Diff line change @@ -207,19 +207,68 @@ test('@apply error with nested @anyatrulehere', async () => {
207
207
}
208
208
209
209
let css = `
210
- @tailwind components;
211
- @tailwind utilities;
210
+ @tailwind components;
211
+ @tailwind utilities;
212
212
213
- @layer components {
214
- .foo {
215
- @genie {
216
- @apply text-black;
213
+ @layer components {
214
+ .foo {
215
+ @genie {
216
+ @apply text-black;
217
+ }
217
218
}
218
219
}
219
- }
220
- `
220
+ `
221
221
222
222
await expect ( run ( css , config ) ) . rejects . toThrowError (
223
223
'@apply is not supported within nested at-rules like @genie'
224
224
)
225
225
} )
226
+
227
+ test ( '@apply error when using .group utility' , async ( ) => {
228
+ let config = {
229
+ darkMode : 'class' ,
230
+ purge : [ { raw : '<div class="foo"></div>' } ] ,
231
+ corePlugins : { preflight : false } ,
232
+ plugins : [ ] ,
233
+ }
234
+
235
+ let css = `
236
+ @tailwind components;
237
+ @tailwind utilities;
238
+
239
+ @layer components {
240
+ .foo {
241
+ @apply group;
242
+ }
243
+ }
244
+ `
245
+
246
+ await expect ( run ( css , config ) ) . rejects . toThrowError (
247
+ `@apply should not be used with the 'group' utility`
248
+ )
249
+ } )
250
+
251
+ test ( '@apply error when using a prefixed .group utility' , async ( ) => {
252
+ let config = {
253
+ prefix : 'tw-' ,
254
+ darkMode : 'class' ,
255
+ purge : [ { raw : '<div class="foo"></div>' } ] ,
256
+ corePlugins : { preflight : false } ,
257
+ plugins : [ ] ,
258
+ }
259
+
260
+ let css = `
261
+ @tailwind components;
262
+ @tailwind utilities;
263
+
264
+ @layer components {
265
+ .foo {
266
+ @apply tw-group;
267
+ }
268
+ }
269
+ `
270
+
271
+ await expect ( run ( css , config ) ) . rejects . toThrowError (
272
+ `@apply should not be used with the 'tw-group' utility`
273
+ )
274
+ } )
You can’t perform that action at this time.
0 commit comments