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

Commit 836ae9a

Browse files
committed
Merge branch 'master' of github.com:tailwindlabs/tailwindcss-jit
2 parents d054a53 + 07d0e82 commit 836ae9a

File tree

4 files changed

+53
-35
lines changed

4 files changed

+53
-35
lines changed

src/index.test.css

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
}
3333
.apply-components {
3434
width: 100%;
35-
margin-left: auto;
36-
margin-right: auto;
3735
}
3836
@media (min-width: 640px) {
3937
.apply-components {
@@ -60,6 +58,10 @@
6058
max-width: 1536px;
6159
}
6260
}
61+
.apply-components {
62+
margin-left: auto;
63+
margin-right: auto;
64+
}
6365
.drop-empty-rules:hover {
6466
font-weight: 700;
6567
}
@@ -99,6 +101,22 @@
99101
font-weight: 400;
100102
}
101103
}
104+
.apply-order-a {
105+
margin: 1.25rem;
106+
margin-top: 1.5rem;
107+
}
108+
.apply-order-b {
109+
margin: 1.25rem;
110+
margin-top: 1.5rem;
111+
}
112+
.dark .dark\:group:hover .apply-dark-group-example-a {
113+
--tw-bg-opacity: 1;
114+
background-color: rgba(16, 185, 129, var(--tw-bg-opacity));
115+
}
116+
.group:hover .group-hover\:dark .apply-dark-group-example-b {
117+
--tw-bg-opacity: 1;
118+
background-color: rgba(16, 185, 129, var(--tw-bg-opacity));
119+
}
102120
@media (min-width: 640px) {
103121
@media (prefers-reduced-motion: no-preference) {
104122
.group:active .crazy-example:focus {

src/index.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ test('it works', () => {
110110
@apply font-bold hover:font-normal;
111111
}
112112
}
113+
.apply-order-a {
114+
@apply m-5 mt-6;
115+
}
116+
.apply-order-b {
117+
@apply mt-6 m-5;
118+
}
119+
.apply-dark-group-example-a {
120+
@apply dark:group-hover:bg-green-500;
121+
}
122+
.apply-dark-group-example-b {
123+
@apply group-hover:dark:bg-green-500;
124+
}
113125
.crazy-example {
114126
@apply sm:motion-safe:group-active:focus:opacity-10;
115127
}

src/lib/collapseAdjacentRules.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
let comparisonMap = {
2+
atrule: 'params',
3+
rule: 'selector',
4+
}
5+
let types = new Set(Object.keys(comparisonMap))
6+
17
function collapseAdjacentRules(context) {
28
return (root) => {
39
let currentRule = null
410
root.each((node) => {
5-
if (node.type !== 'atrule') {
11+
if (!types.has(node.type)) {
612
currentRule = null
713
return
814
}
@@ -12,7 +18,8 @@ function collapseAdjacentRules(context) {
1218
return
1319
}
1420

15-
if (node.params === currentRule.params) {
21+
let property = comparisonMap[node.type]
22+
if (node[property] === currentRule[property]) {
1623
currentRule.append(node.nodes)
1724
node.remove()
1825
} else {

src/lib/expandApplyAtRules.js

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const postcss = require('postcss')
21
const generateRules = require('./generateRules')
32
const { bigSign, toPostCssNode, isPlainObject } = require('./utils')
43
const escape = require('tailwindcss/lib/util/escapeClassName').default
@@ -68,40 +67,22 @@ function expandApplyAtRules(context) {
6867
}
6968

7069
let rules = context.classCache.get(applyCandidate)
71-
for (let [{ sort, layer }, [selector, rule]] of rules) {
72-
// Nested rules...
73-
if (!isPlainObject(rule)) {
74-
siblings.push([
75-
{ sort, layer },
76-
toPostCssNode(
77-
[selector, updateSelectors(rule, apply, applyCandidate)],
78-
context.postCssNodeCache
79-
),
80-
])
81-
} else {
82-
let appliedSelector = replaceSelector(apply.parent.selector, selector, applyCandidate)
83-
84-
if (appliedSelector !== apply.parent.selector) {
85-
siblings.push([
86-
{ sort, layer },
87-
toPostCssNode([appliedSelector, rule], context.postCssNodeCache),
88-
])
89-
continue
90-
}
91-
92-
// Add declarations directly
93-
for (let property in rule) {
94-
apply.before(postcss.decl({ prop: property, value: rule[property] }))
95-
}
96-
}
70+
for (let [meta, [selector, rule]] of rules) {
71+
siblings.push([
72+
meta,
73+
toPostCssNode(
74+
!isPlainObject(rule)
75+
? [selector, updateSelectors(rule, apply, applyCandidate)]
76+
: [replaceSelector(apply.parent.selector, selector, applyCandidate), rule],
77+
context.postCssNodeCache
78+
),
79+
])
9780
}
9881
}
9982

10083
// Inject the rules, sorted, correctly
101-
for (let [{ sort }, sibling] of siblings.sort(([{ sort: a }], [{ sort: z }]) =>
102-
bigSign(z - a)
103-
)) {
104-
// `apply.parent` is refering to the node at `.abc` in: .abc { @apply mt-2 }
84+
for (let [, sibling] of siblings.sort(([a], [z]) => bigSign(z.sort - a.sort))) {
85+
// `apply.parent` is referring to the node at `.abc` in: .abc { @apply mt-2 }
10586
apply.parent.after(sibling)
10687
}
10788

0 commit comments

Comments
 (0)