Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions packages/tailwindcss/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/tailwindcss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading