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

Commit 78e1699

Browse files
committed
Customize error message for nested @screen and nested @apply
1 parent 90f4ee3 commit 78e1699

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/lib/expandApplyAtRules.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ function processApply(root, context) {
154154
let [applyCandidates, important] = extractApplyCandidates(apply.params)
155155

156156
if (apply.parent.type === 'atrule') {
157+
if (apply.parent.name === 'screen') {
158+
const screenType = apply.parent.params
159+
160+
throw apply.error(
161+
`@apply nested inside @screen is not supported. We suggest you write this as @apply ${applyCandidates.map(c => `${screenType}:${c}`).join(' ')} instead.`
162+
)
163+
}
164+
157165
throw apply.error(
158166
`@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`
159167
)

tests/10-apply.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,38 @@ test('@apply error with unknown utility', async () => {
163163

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

0 commit comments

Comments
 (0)