Don't error on @apply with extra whitespace (#13144)

* Don't crash on @apply with extra whitespace

* Update changelog

---------

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
This commit is contained in:
Adam Wathan 2024-03-07 22:00:15 -05:00 committed by GitHub
parent eca02424f5
commit 0a57d33a7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 0 deletions

View File

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- Don't error on `@apply` with leading/trailing whitespace ([#13144](https://github.com/tailwindlabs/tailwindcss/pull/13144))
## [4.0.0-alpha.6] - 2024-03-07
### Fixed

View File

@ -288,6 +288,22 @@ describe('@apply', () => {
`[Error: Cannot apply unknown utility class: hocus:bg-red-500]`,
)
})
it('should not error with trailing whitespace', () => {
expect(
compileCss(`
@tailwind utilities;
.foo {
@apply flex ;
}
`),
).toMatchInlineSnapshot(`
".foo {
display: flex;
}"
`)
})
})
describe('arbitrary variants', () => {

View File

@ -115,6 +115,7 @@ export function compile(css: string, rawCandidates: string[]) {
if (node.kind === 'rule' && node.selector[0] === '@' && node.selector.startsWith('@apply')) {
let candidates = node.selector
.slice(7 /* Ignore `@apply ` when parsing the selector */)
.trim()
.split(/\s+/g)
// Replace the `@apply` rule with the actual utility classes