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 @@ -204,19 +204,68 @@ test('@apply error with nested @anyatrulehere', async () => {
204
204
}
205
205
206
206
let css = `
207
- @tailwind components;
208
- @tailwind utilities;
207
+ @tailwind components;
208
+ @tailwind utilities;
209
209
210
- @layer components {
211
- .foo {
212
- @genie {
213
- @apply text-black;
210
+ @layer components {
211
+ .foo {
212
+ @genie {
213
+ @apply text-black;
214
+ }
214
215
}
215
216
}
216
- }
217
- `
217
+ `
218
218
219
219
await expect ( run ( css , config ) ) . rejects . toThrowError (
220
220
'@apply is not supported within nested at-rules like @genie'
221
221
)
222
222
} )
223
+
224
+ test ( '@apply error when using .group utility' , async ( ) => {
225
+ let config = {
226
+ darkMode : 'class' ,
227
+ purge : [ { raw : '<div class="foo"></div>' } ] ,
228
+ corePlugins : { preflight : false } ,
229
+ plugins : [ ] ,
230
+ }
231
+
232
+ let css = `
233
+ @tailwind components;
234
+ @tailwind utilities;
235
+
236
+ @layer components {
237
+ .foo {
238
+ @apply group;
239
+ }
240
+ }
241
+ `
242
+
243
+ await expect ( run ( css , config ) ) . rejects . toThrowError (
244
+ `@apply should not be used with the 'group' utility`
245
+ )
246
+ } )
247
+
248
+ test ( '@apply error when using a prefixed .group utility' , async ( ) => {
249
+ let config = {
250
+ prefix : 'tw-' ,
251
+ darkMode : 'class' ,
252
+ purge : [ { raw : '<div class="foo"></div>' } ] ,
253
+ corePlugins : { preflight : false } ,
254
+ plugins : [ ] ,
255
+ }
256
+
257
+ let css = `
258
+ @tailwind components;
259
+ @tailwind utilities;
260
+
261
+ @layer components {
262
+ .foo {
263
+ @apply tw-group;
264
+ }
265
+ }
266
+ `
267
+
268
+ await expect ( run ( css , config ) ) . rejects . toThrowError (
269
+ `@apply should not be used with the 'tw-group' utility`
270
+ )
271
+ } )
You can’t perform that action at this time.
0 commit comments