Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support applying important utilities in JIT #4260

Merged
merged 1 commit into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 1 addition & 3 deletions src/jit/lib/expandApplyAtRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
})
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/jit/lib/generateRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/jit/apply.test.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions tests/jit/apply.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 4 additions & 0 deletions tests/jit/apply.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ test('@apply', () => {
@apply lg:text-2xl;
@apply sm:text-2xl;
}

.important-modifier {
@apply px-4 !rounded-md;
}
}

@layer utilities {
Expand Down