Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Don’t generate duplicate rule implementations
If multiple candidates resolved to the same rule the properties would get added more than once to the same rule.

For instance: class:text-blue-500 class1:text-blue-500 class2:text-blue-500 results in .text-blue-500 having the properties set 3 times.
  • Loading branch information
thecrypticace committed Mar 28, 2021
commit 84404ceb25a9efb7afca2b046ba2a6dee2f68fe3
12 changes: 12 additions & 0 deletions src/lib/generateRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ function inKeyframes(rule) {

function generateRules(candidates, context) {
let allRules = []
let allSelectors = new Set()

for (let candidate of candidates) {
if (context.notClassCache.has(candidate)) {
Expand All @@ -285,8 +286,19 @@ function generateRules(candidates, context) {
continue
}

matches = matches.filter(([_, rule]) => {
return !rule.selector
|| !allSelectors.has(rule.selector)
})

context.classCache.set(candidate, matches)
allRules.push(...matches)

matches.forEach(([_, rule]) => {
if (rule.selector) {
allSelectors.add(rule.selector)
}
})
}

return allRules.map(([{ sort, layer, options }, rule]) => {
Expand Down
2 changes: 2 additions & 0 deletions tests/variants.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,7 @@

<!-- Things that look like variants but are not -->
<h1 class:text-blue-500={shouldBeBlue}></h1>
<h1 class1:text-blue-500={shouldBeBlue}></h1>
<h1 class2:text-blue-500={shouldBeBlue}></h1>
</body>
</html>