Skip to content

Commit e0f6fee

Browse files
thecrypticaceRobinMalfait
authored andcommitted
Don’t allow utility-based @apply to be used with a body
1 parent df02995 commit e0f6fee

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

packages/tailwindcss/src/apply.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,19 @@ export function substituteAtApply(ast: AstNode[], designSystem: DesignSystem) {
201201
)
202202
}
203203

204+
// If we find a dashed ident *here* it means that someone is trying
205+
// to use mixins and our `@apply` behavior together.
206+
//
207+
// This is considered invalid usage and we want to inform the user
208+
// as such.
209+
let hasBody = child.nodes.length > 0
210+
211+
if (hasBody && normalIdents.length) {
212+
let list = normalIdents.join(' ')
213+
214+
throw new Error(`The rule \`@apply ${list}\` must not have a body.`)
215+
}
216+
204217
// Replace the `@apply` rule with the actual utility classes
205218
{
206219
// Parse the candidates to an AST that we can replace the `@apply` rule

packages/tailwindcss/src/index.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,20 @@ describe('@apply', () => {
910910
`[Error: You cannot use \`@apply\` with both mixins and utilities. Please move \`@apply --my-mixin-1\` into a separate rule.]`,
911911
)
912912
})
913+
914+
it('should error when used with a body', async () => {
915+
await expect(
916+
compile(css`
917+
.foo {
918+
@apply underline {
919+
color: red;
920+
}
921+
}
922+
`),
923+
).rejects.toThrowErrorMatchingInlineSnapshot(
924+
`[Error: The rule \`@apply underline\` must not have a body.]`,
925+
)
926+
})
913927
})
914928

915929
describe('arbitrary variants', () => {

0 commit comments

Comments
 (0)