Skip to content

Allow :global selector around @tailwind #12635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 10 additions & 1 deletion src/lib/detectNesting.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@ function isAtLayer(node) {
return node.type === 'atrule' && node.name === 'layer'
}

function isGlobalRoot(node) {
if (node.selector !== ':global') return false

return node.parent && isRoot(node.parent)
}

export default function (_context) {
return (root, result) => {
let found = false

root.walkAtRules('tailwind', (node) => {
if (found) return false

if (node.parent && !(isRoot(node.parent) || isAtLayer(node.parent))) {
if (
node.parent &&
!(isRoot(node.parent) || isAtLayer(node.parent) || isGlobalRoot(node.parent))
) {
found = true
node.warn(
result,
Expand Down
35 changes: 35 additions & 0 deletions tests/detect-nesting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,41 @@ it('should not warn when we detect nested css inside css @layer rules', () => {
})
})

it('should not warn when we detect global @layer rules', () => {
let config = {
content: [{ raw: html`<div class="underline"></div>` }],
}

let input = css`
:global {
@layer tw-base, tw-components, tw-utilities;
@layer tw-utilities {
@tailwind utilities;
}
}
`

return run(input, config).then((result) => {
expect(result.messages).toHaveLength(0)
})
})

it('should not warn when we detect global @tailwind at rules', () => {
let config = {
content: [{ raw: html`<div class="text-center"></div>` }],
}

let input = css`
:global {
@tailwind utilities;
}
`

return run(input, config).then((result) => {
expect(result.messages).toHaveLength(0)
})
})

it('should warn when we detect namespaced @tailwind at rules', () => {
let config = {
content: [{ raw: html`<div class="text-center"></div>` }],
Expand Down