Skip to content

Commit 33fbad9

Browse files
authored
Support applying important utilities in JIT (#4260)
1 parent 2d9e2d9 commit 33fbad9

File tree

5 files changed

+12
-4
lines changed

5 files changed

+12
-4
lines changed

src/jit/lib/expandApplyAtRules.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ function buildApplyCache(applyCandidates, context) {
3030
return context.applyClassCache
3131
}
3232

33-
// TODO: Apply `!important` stuff correctly instead of just skipping it
3433
function extractApplyCandidates(params) {
3534
let candidates = params.split(/[\s\t\n]+/g)
3635

@@ -143,7 +142,6 @@ function processApply(root, context) {
143142
.join(', ')
144143
}
145144

146-
/** @type {Map<import('postcss').Node, [string, boolean, import('postcss').Node[]][]>} */
147145
let perParentApplies = new Map()
148146

149147
// Collect all apply candidates and their rules
@@ -197,7 +195,7 @@ function processApply(root, context) {
197195
rule.selector = replaceSelector(parent.selector, rule.selector, applyCandidate)
198196

199197
rule.walkDecls((d) => {
200-
d.important = important
198+
d.important = meta.important || important
201199
})
202200
})
203201
}

src/jit/lib/generateRules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function applyImportant(matches) {
7979
})
8080
r.walkDecls((d) => (d.important = true))
8181
})
82-
result.push([meta, container.nodes[0]])
82+
result.push([{ ...meta, important: true }, container.nodes[0]])
8383
}
8484

8585
return result

tests/jit/apply.test.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@ h2 {
323323
line-height: 2rem;
324324
}
325325
}
326+
.important-modifier {
327+
border-radius: 0.375rem !important;
328+
padding-left: 1rem;
329+
padding-right: 1rem;
330+
}
326331
@keyframes spin {
327332
to {
328333
transform: rotate(360deg);

tests/jit/apply.test.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<div class="recursive-apply-c"></div>
3333
<div class="use-with-other-properties-base use-with-other-properties-component"></div>
3434
<div class="add-sibling-properties"></div>
35+
<div class="important-modifier"></div>
3536
<div class="a b"></div>
3637
<div class="foo"></div>
3738
<div class="bar"></div>

tests/jit/apply.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ test('@apply', () => {
119119
@apply lg:text-2xl;
120120
@apply sm:text-2xl;
121121
}
122+
123+
.important-modifier {
124+
@apply px-4 !rounded-md;
125+
}
122126
}
123127
124128
@layer utilities {

0 commit comments

Comments
 (0)