Skip to content

Commit

Permalink
Fix application of rules with multiple matches of differing selectors
Browse files Browse the repository at this point in the history
`-foo-1` and `foo-1` are both matches for the class `-foo-1` but `@apply` only wants the first one. It would remove the second one and cause an error because it’s an entirely separate match that had it’s only rule removed.
  • Loading branch information
thecrypticace committed Aug 4, 2022
1 parent 2bfd3e7 commit 57720aa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
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;
}
`)
})

0 comments on commit 57720aa

Please sign in to comment.