Skip to content

Commit 0b24530

Browse files
committed
hide nesting warnings in root or @layer nodes
1 parent 3a8e95d commit 0b24530

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/lib/detectNesting.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
function isRoot(node) {
2+
return node.type === 'root'
3+
}
4+
5+
function isAtLayer(node) {
6+
return node.type === 'atrule' && node.name === 'layer'
7+
}
8+
19
export default function (_context) {
210
return (root, result) => {
311
let found = false
412

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

8-
if (node.parent && node.parent.type !== 'root') {
16+
if (node.parent && !(isRoot(node.parent) || isAtLayer(node.parent))) {
917
found = true
1018
node.warn(
1119
result,

tests/detect-nesting.test.js

+25
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,31 @@ it('should warn when we detect nested css', () => {
2929
})
3030
})
3131

32+
it('should not warn when we detect nested css inside css @layer rules', () => {
33+
let config = {
34+
content: [{ raw: html`<div class="underline"></div>` }],
35+
}
36+
37+
let input = css`
38+
@layer tw-base, tw-components, tw-utilities;
39+
@layer tw-utilities {
40+
@tailwind utilities;
41+
}
42+
`
43+
44+
return run(input, config).then((result) => {
45+
expect(result.css).toMatchFormattedCss(css`
46+
@layer tw-base, tw-components, tw-utilities;
47+
@layer tw-utilities {
48+
.underline {
49+
text-decoration-line: underline;
50+
}
51+
}
52+
`)
53+
expect(result.messages).toHaveLength(0)
54+
})
55+
})
56+
3257
it('should warn when we detect namespaced @tailwind at rules', () => {
3358
let config = {
3459
content: [{ raw: html`<div class="text-center"></div>` }],

0 commit comments

Comments
 (0)