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

Commit 90f4ee3

Browse files
committed
Add error for nested at rule + nested apply
1 parent d89baaa commit 90f4ee3

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/lib/expandApplyAtRules.js

+6
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ function processApply(root, context) {
153153

154154
let [applyCandidates, important] = extractApplyCandidates(apply.params)
155155

156+
if (apply.parent.type === 'atrule') {
157+
throw apply.error(
158+
`@apply only works for elements and classes. Nesting inside an @${apply.parent.name} is not supported. Please move the @${apply.parent.name} around the element/class selector`
159+
)
160+
}
161+
156162
for (let applyCandidate of applyCandidates) {
157163
if (!applyClassCache.has(applyCandidate)) {
158164
throw apply.error(

tests/10-apply.test.js

+26
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,29 @@ test('@apply error with unknown utility', async () => {
163163

164164
await expect(run(css, config)).rejects.toThrowError("class does not exist")
165165
})
166+
test('@apply error with nested @anyatrulehere', async () => {
167+
let config = {
168+
// TODO: Remove this. Some kind of caching causes multiple tests in the same file to break.
169+
__name: "at-anything",
170+
171+
darkMode: 'class',
172+
purge: [path.resolve(__dirname, './10-apply.test.html')],
173+
corePlugins: { preflight: false },
174+
plugins: [],
175+
}
176+
177+
let css = `
178+
@tailwind components;
179+
@tailwind utilities;
180+
181+
@layer components {
182+
.foo {
183+
@genie {
184+
@apply text-black;
185+
}
186+
}
187+
}
188+
`
189+
190+
await expect(run(css, config)).rejects.toThrowError("Nesting inside an @genie is not supported")
191+
})

0 commit comments

Comments
 (0)