Skip to content

Commit

Permalink
throw an error when applying the .group utility (aot mode)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinMalfait committed Jun 16, 2021
1 parent 49cb426 commit 3513952
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib/substituteClassApplyAtRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ function makeExtractUtilityRules(css, lookupTree, config) {
const prefixedUtilityName = prefixSelector(config.prefix, `.${utilityName}`).slice(1)

const prefixedUtility = getUtility(prefixedUtilityName)
if (
utilityName === 'group' ||
utilityName === prefixSelector(config.prefix, '.group').slice(1)
) {
// TODO: Link to specific documentation page with error code.
throw rule.error(`@apply should not be used with the '${utilityName}' utility`)
}

if (prefixedUtility !== undefined) {
throw rule.error(
`The \`${utilityName}\` class does not exist, but \`${prefixedUtilityName}\` does. Did you forget the prefix?`
Expand Down
41 changes: 41 additions & 0 deletions tests/applyAtRule.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1403,3 +1403,44 @@ test('lookup tree is correctly cached based on used tailwind atrules', async ()
.foo { margin-top: 1rem; }
`)
})

test('@apply error when using .group utility', async () => {
let config = {
purge: [],
corePlugins: { preflight: false },
plugins: [],
}

let css = `
@layer components {
.foo {
@apply group;
}
}
`

await expect(run(css, config)).rejects.toThrowError(
`@apply should not be used with the 'group' utility`
)
})

test('@apply error when using prefixed .group utility', async () => {
let config = {
prefix: 'tw-',
purge: [],
corePlugins: { preflight: false },
plugins: [],
}

let css = `
@layer components {
.foo {
@apply tw-group;
}
}
`

await expect(run(css, config)).rejects.toThrowError(
`@apply should not be used with the 'tw-group' utility`
)
})

0 comments on commit 3513952

Please sign in to comment.