Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Commit 3e3c101

Browse files
committed
Fallback to non variant matches when no matching variant exists
Svelte’s dynamic class syntax looks like this: <h1 class:text-blue-500={shouldBeBlue}></h1> We were picking up `class:text-blue-500` as a variant. However `class` is not a registered variant. In this case we were discarding the already matched rules for text-blue-500. In this case we want to match them anyway.
1 parent d47902f commit 3e3c101

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/lib/generateRules.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function applyVariant(variant, matches, context) {
146146
return result
147147
}
148148

149-
return []
149+
return matches
150150
}
151151

152152
function parseRules(rule, cache, options = {}) {

tests/variants.test.css

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
--tw-ring-offset-shadow: 0 0 #0000;
88
--tw-ring-shadow: 0 0 #0000;
99
}
10+
.text-blue-500 {
11+
--tw-text-opacity: 1;
12+
color: rgba(59, 130, 246, var(--tw-text-opacity));
13+
}
1014
.shadow-md {
1115
--tw-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
1216
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000),

tests/variants.test.html

+3
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,8 @@
6464
<div class="lg:dark:shadow-md"></div>
6565
<div class="xl:dark:disabledshadow-md"></div>
6666
<div class="2xl:dark:motion-safe:focus-within:shadow-md"></div>
67+
68+
<!-- Things that look like variants but are not -->
69+
<h1 class:text-blue-500={shouldBeBlue}></h1>
6770
</body>
6871
</html>

0 commit comments

Comments
 (0)