File tree Expand file tree Collapse file tree 3 files changed +73
-11
lines changed Expand file tree Collapse file tree 3 files changed +73
-11
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 @@ -261,7 +261,6 @@ export default function resolveConfig(configs) {
261
261
let allConfigs = [
262
262
...extractPluginConfigs ( configs ) ,
263
263
{
264
- content : [ ] ,
265
264
prefix : '' ,
266
265
important : false ,
267
266
separator : ':' ,
@@ -302,10 +301,10 @@ function normalizeConfig(config) {
302
301
content : ( ( ) => {
303
302
let { content, purge } = config
304
303
305
- if ( Array . isArray ( content ) ) return content
306
- if ( Array . isArray ( content ?. content ) ) return content . content
307
304
if ( Array . isArray ( purge ) ) return purge
308
305
if ( Array . isArray ( purge ?. content ) ) return purge . content
306
+ if ( Array . isArray ( content ) ) return content
307
+ if ( Array . isArray ( content ?. content ) ) return content . content
309
308
310
309
return [ ]
311
310
} ) ( ) ,
Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ function run(input, config = {}) {
11
11
} )
12
12
}
13
13
14
+ function css ( templates ) {
15
+ return templates . join ( '' )
16
+ }
17
+
14
18
test ( '@apply' , ( ) => {
15
19
let config = {
16
20
darkMode : 'class' ,
@@ -207,19 +211,68 @@ test('@apply error with nested @anyatrulehere', async () => {
207
211
}
208
212
209
213
let css = `
210
- @tailwind components;
211
- @tailwind utilities;
214
+ @tailwind components;
215
+ @tailwind utilities;
212
216
213
- @layer components {
214
- .foo {
215
- @genie {
216
- @apply text-black;
217
+ @layer components {
218
+ .foo {
219
+ @genie {
220
+ @apply text-black;
221
+ }
217
222
}
218
223
}
219
- }
220
- `
224
+ `
221
225
222
226
await expect ( run ( css , config ) ) . rejects . toThrowError (
223
227
'@apply is not supported within nested at-rules like @genie'
224
228
)
225
229
} )
230
+
231
+ test ( '@apply error when using .group utility' , async ( ) => {
232
+ let config = {
233
+ darkMode : 'class' ,
234
+ content : [ { raw : '<div class="foo"></div>' } ] ,
235
+ corePlugins : { preflight : false } ,
236
+ plugins : [ ] ,
237
+ }
238
+
239
+ let input = css `
240
+ @tailwind components;
241
+ @tailwind utilities;
242
+
243
+ @layer components {
244
+ .foo {
245
+ @apply group;
246
+ }
247
+ }
248
+ `
249
+
250
+ await expect ( run ( input , config ) ) . rejects . toThrowError (
251
+ `@apply should not be used with the 'group' utility`
252
+ )
253
+ } )
254
+
255
+ test ( '@apply error when using a prefixed .group utility' , async ( ) => {
256
+ let config = {
257
+ prefix : 'tw-' ,
258
+ darkMode : 'class' ,
259
+ content : [ { raw : '<div class="foo"></div>' } ] ,
260
+ corePlugins : { preflight : false } ,
261
+ plugins : [ ] ,
262
+ }
263
+
264
+ let css = `
265
+ @tailwind components;
266
+ @tailwind utilities;
267
+
268
+ @layer components {
269
+ .foo {
270
+ @apply tw-group;
271
+ }
272
+ }
273
+ `
274
+
275
+ await expect ( run ( css , config ) ) . rejects . toThrowError (
276
+ `@apply should not be used with the 'tw-group' utility`
277
+ )
278
+ } )
You can’t perform that action at this time.
0 commit comments