Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add error for nested at rule + nested apply
  • Loading branch information
thecrypticace committed Mar 26, 2021
commit 90f4ee36624fb8a0a76c2dae31cad002fa88f8af
6 changes: 6 additions & 0 deletions src/lib/expandApplyAtRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ function processApply(root, context) {

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

if (apply.parent.type === 'atrule') {
throw apply.error(
`@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`
)
}

for (let applyCandidate of applyCandidates) {
if (!applyClassCache.has(applyCandidate)) {
throw apply.error(
Expand Down
26 changes: 26 additions & 0 deletions tests/10-apply.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,29 @@ test('@apply error with unknown utility', async () => {

await expect(run(css, config)).rejects.toThrowError("class does not exist")
})
test('@apply error with nested @anyatrulehere', async () => {
let config = {
// TODO: Remove this. Some kind of caching causes multiple tests in the same file to break.
__name: "at-anything",

darkMode: 'class',
purge: [path.resolve(__dirname, './10-apply.test.html')],
corePlugins: { preflight: false },
plugins: [],
}

let css = `
@tailwind components;
@tailwind utilities;

@layer components {
.foo {
@genie {
@apply text-black;
}
}
}
`

await expect(run(css, config)).rejects.toThrowError("Nesting inside an @genie is not supported")
})