Skip to content

Commit 21413ea

Browse files
committed
Allow all classes for @apply
1 parent 00f60e6 commit 21413ea

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/lib/expandApplyAtRules.js

+21
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,27 @@ function processApply(root, context) {
122122
// Fill up some caches!
123123
let applyClassCache = buildApplyCache(applyCandidates, context)
124124

125+
// Collect all classes for @apply rules.
126+
root.walk((node) => {
127+
if (node.selector && node.selector[0] === '.') {
128+
const name = node.selector.substring(1)
129+
130+
// Ignore unused candidates.
131+
if (applyCandidates.has(name) && !applyClassCache.has(name)) {
132+
applyClassCache.set(name, [
133+
[
134+
{
135+
sort: BigInt(context.layerOrder.user),
136+
layer: 'user',
137+
options: {},
138+
},
139+
node,
140+
],
141+
])
142+
}
143+
}
144+
})
145+
125146
/**
126147
* When we have an apply like this:
127148
*

tests/apply.test.js

+37
Original file line numberDiff line numberDiff line change
@@ -616,3 +616,40 @@ it('rules with vendor prefixes are still separate when optimizing defaults rules
616616
`)
617617
})
618618
})
619+
620+
it('should pickup all classes', () => {
621+
let config = {
622+
content: [{ raw: html`<div class="foo"></div>` }],
623+
plugins: [],
624+
}
625+
626+
let input = css`
627+
.bop {
628+
color: red;
629+
}
630+
631+
.bar {
632+
background-color: blue;
633+
}
634+
635+
.foo {
636+
@apply absolute bar bop;
637+
}
638+
`
639+
640+
return run(input, config).then((result) => {
641+
return expect(result.css).toMatchFormattedCss(css`
642+
.bop {
643+
color: red;
644+
}
645+
.bar {
646+
background-color: blue;
647+
}
648+
.foo {
649+
position: absolute;
650+
background-color: blue;
651+
color: red;
652+
}
653+
`)
654+
})
655+
})

0 commit comments

Comments
 (0)