Support applying important utilities in JIT (#4260)

This commit is contained in:
Adam Wathan 2021-05-06 13:52:26 -04:00
parent 8e49526e6f
commit 114baeeef1
5 changed files with 12 additions and 4 deletions

View File

@ -30,7 +30,6 @@ function buildApplyCache(applyCandidates, context) {
return context.applyClassCache
}
// TODO: Apply `!important` stuff correctly instead of just skipping it
function extractApplyCandidates(params) {
let candidates = params.split(/[\s\t\n]+/g)
@ -143,7 +142,6 @@ function processApply(root, context) {
.join(', ')
}
/** @type {Map<import('postcss').Node, [string, boolean, import('postcss').Node[]][]>} */
let perParentApplies = new Map()
// Collect all apply candidates and their rules
@ -197,7 +195,7 @@ function processApply(root, context) {
rule.selector = replaceSelector(parent.selector, rule.selector, applyCandidate)
rule.walkDecls((d) => {
d.important = important
d.important = meta.important || important
})
})
}

View File

@ -79,7 +79,7 @@ function applyImportant(matches) {
})
r.walkDecls((d) => (d.important = true))
})
result.push([meta, container.nodes[0]])
result.push([{ ...meta, important: true }, container.nodes[0]])
}
return result

View File

@ -323,6 +323,11 @@ h2 {
line-height: 2rem;
}
}
.important-modifier {
border-radius: 0.375rem !important;
padding-left: 1rem;
padding-right: 1rem;
}
@keyframes spin {
to {
transform: rotate(360deg);

View File

@ -32,6 +32,7 @@
<div class="recursive-apply-c"></div>
<div class="use-with-other-properties-base use-with-other-properties-component"></div>
<div class="add-sibling-properties"></div>
<div class="important-modifier"></div>
<div class="a b"></div>
<div class="foo"></div>
<div class="bar"></div>

View File

@ -119,6 +119,10 @@ test('@apply', () => {
@apply lg:text-2xl;
@apply sm:text-2xl;
}
.important-modifier {
@apply px-4 !rounded-md;
}
}
@layer utilities {