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

Commit 2964d86

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

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/lib/expandApplyAtRules.js

+8
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

+28
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,34 @@ 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+
plugins: [],
176+
}
177+
178+
let css = `
179+
@tailwind components;
180+
@tailwind utilities;
181+
182+
@layer components {
183+
.foo {
184+
@screen md {
185+
@apply text-black;
186+
}
187+
}
188+
}
189+
`
190+
191+
await expect(run(css, config)).rejects.toThrowError("@apply nested inside @screen is not supported")
192+
})
193+
166194
test('@apply error with nested @anyatrulehere', async () => {
167195
let config = {
168196
// TODO: Remove this. Some kind of caching causes multiple tests in the same file to break.

0 commit comments

Comments
 (0)