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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix @apply of user utilities when negative and non-negative versions both exist #9027

Merged
merged 2 commits into from Aug 4, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Don鈥檛 prefix classes within reused arbitrary variants ([#8992](https://github.com/tailwindlabs/tailwindcss/pull/8992))
- Fix usage of alpha values inside single-named colors that are functions ([#9008](https://github.com/tailwindlabs/tailwindcss/pull/9008))
- Fix `@apply` of user utilities when negative and non-negative versions both exist ([#9027](https://github.com/tailwindlabs/tailwindcss/pull/9027))

### Changed

Expand Down
6 changes: 6 additions & 0 deletions src/lib/expandApplyAtRules.js
Expand Up @@ -499,6 +499,12 @@ function processApply(root, context, localCache) {
})
}

// It could be that the node we were inserted was removed because the class didn't match
// If that was the *only* rule in the parent, then we have nothing add so we skip it
if (!root.nodes[0]) {
continue
}

// Insert it
siblings.push([
// Ensure that when we are sorting, that we take the layer order into account
Expand Down
36 changes: 36 additions & 0 deletions tests/apply.test.js
Expand Up @@ -1548,3 +1548,39 @@ it('apply + user CSS + selector variants (like group) + important selector (2)',
}
`)
})

it('can apply user utilities that start with a dash', async () => {
let config = {
content: [{ raw: html`<div class="foo-1 -foo-1 new-class"></div>` }],
plugins: [],
}

let input = css`
@tailwind utilities;
@layer utilities {
.foo-1 {
margin: 10px;
}
.-foo-1 {
margin: -15px;
}
.new-class {
@apply -foo-1;
}
}
`

let result = await run(input, config)

expect(result.css).toMatchFormattedCss(css`
.foo-1 {
margin: 10px;
}
.-foo-1 {
margin: -15px;
}
.new-class {
margin: -15px;
}
`)
})