Skip to content

Commit 49cb426

Browse files
committed
throw an error when applying the .group utility (jit mode)
1 parent 243e881 commit 49cb426

File tree

2 files changed

+67
-8
lines changed

2 files changed

+67
-8
lines changed

src/jit/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
@@ -204,19 +204,68 @@ test('@apply error with nested @anyatrulehere', async () => {
204204
}
205205

206206
let css = `
207-
@tailwind components;
208-
@tailwind utilities;
207+
@tailwind components;
208+
@tailwind utilities;
209209
210-
@layer components {
211-
.foo {
212-
@genie {
213-
@apply text-black;
210+
@layer components {
211+
.foo {
212+
@genie {
213+
@apply text-black;
214+
}
214215
}
215216
}
216-
}
217-
`
217+
`
218218

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

0 commit comments

Comments
 (0)