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

Add error messages for nested at-rules & apply #161

Merged
merged 5 commits into from
Mar 26, 2021
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
Tweak error messages
  • Loading branch information
adamwathan committed Mar 26, 2021
commit deb0d7ef268b06c4622eb36dfaf20b7168daf445
6 changes: 4 additions & 2 deletions src/lib/expandApplyAtRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,14 @@ function processApply(root, context) {
const screenType = apply.parent.params

throw apply.error(
`@apply nested inside @screen is not supported. We suggest you write this as @apply ${applyCandidates.map(c => `${screenType}:${c}`).join(' ')} instead.`
`@apply is not supported within nested at-rules like @screen. We suggest you write this as @apply ${applyCandidates
.map((c) => `${screenType}:${c}`)
.join(' ')} instead.`
)
}

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`
`@apply is not supported within nested at-rules like @${apply.parent.name}. You can fix this by un-nesting @${apply.parent.name}.`
)
}

Expand Down
12 changes: 8 additions & 4 deletions tests/10-apply.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function run(input, config = {}) {
const { currentTestName } = expect.getState()

return postcss([tailwind(config)]).process(input, {
from: `${path.resolve(__filename)}?test=${currentTestName}`
from: `${path.resolve(__filename)}?test=${currentTestName}`,
})
}

Expand Down Expand Up @@ -162,7 +162,7 @@ test('@apply error with unknown utility', async () => {
}
`

await expect(run(css, config)).rejects.toThrowError("class does not exist")
await expect(run(css, config)).rejects.toThrowError('class does not exist')
})

test('@apply error with nested @screen', async () => {
Expand All @@ -186,7 +186,9 @@ test('@apply error with nested @screen', async () => {
}
`

await expect(run(css, config)).rejects.toThrowError("@apply nested inside @screen is not supported")
await expect(run(css, config)).rejects.toThrowError(
'@apply is not supported within nested at-rules like @screen'
)
})

test('@apply error with nested @anyatrulehere', async () => {
Expand All @@ -210,5 +212,7 @@ test('@apply error with nested @anyatrulehere', async () => {
}
`

await expect(run(css, config)).rejects.toThrowError("Nesting inside an @genie is not supported")
await expect(run(css, config)).rejects.toThrowError(
'@apply is not supported within nested at-rules like @genie'
)
})