Skip to content

Commit 0303a12

Browse files
committed
throw an error when applying the .group utility (jit mode)
1 parent 36a02ed commit 0303a12

File tree

2 files changed

+67
-8
lines changed

2 files changed

+67
-8
lines changed

src/lib/expandApplyAtRules.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { resolveMatches } from './generateRules'
33
import bigSign from '../util/bigSign'
44
import escapeClassName from '../util/escapeClassName'
55

6+
function prefix(context, selector) {
7+
let prefix = context.tailwindConfig.prefix
8+
return typeof prefix === 'function' ? prefix(selector) : prefix + selector
9+
}
10+
611
function buildApplyCache(applyCandidates, context) {
712
for (let candidate of applyCandidates) {
813
if (context.notClassCache.has(candidate) || context.applyClassCache.has(candidate)) {
@@ -170,6 +175,11 @@ function processApply(root, context) {
170175

171176
for (let applyCandidate of applyCandidates) {
172177
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+
173183
throw apply.error(
174184
`The \`${applyCandidate}\` class does not exist. If \`${applyCandidate}\` is a custom class, make sure it is defined within a \`@layer\` directive.`
175185
)

tests/jit/apply.test.js

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,68 @@ test('@apply error with nested @anyatrulehere', async () => {
207207
}
208208

209209
let css = `
210-
@tailwind components;
211-
@tailwind utilities;
210+
@tailwind components;
211+
@tailwind utilities;
212212
213-
@layer components {
214-
.foo {
215-
@genie {
216-
@apply text-black;
213+
@layer components {
214+
.foo {
215+
@genie {
216+
@apply text-black;
217+
}
217218
}
218219
}
219-
}
220-
`
220+
`
221221

222222
await expect(run(css, config)).rejects.toThrowError(
223223
'@apply is not supported within nested at-rules like @genie'
224224
)
225225
})
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+
})

0 commit comments

Comments
 (0)