Skip to content
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

Allow direct nesting in root or @layer nodes #10229

Merged
merged 2 commits into from
Jan 3, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix missing `string[]` in the `theme.dropShadow` types ([#10072](https://github.com/tailwindlabs/tailwindcss/pull/10072))
- Update list of length units ([#10100](https://github.com/tailwindlabs/tailwindcss/pull/10100))
- Fix not matching arbitrary properties when closely followed by square brackets ([#10212](https://github.com/tailwindlabs/tailwindcss/pull/10212))
- Allow direct nesting in `root` or `@layer` nodes ([#10229](https://github.com/tailwindlabs/tailwindcss/pull/10229))

### Changed

Expand Down
10 changes: 9 additions & 1 deletion src/lib/detectNesting.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
function isRoot(node) {
return node.type === 'root'
}

function isAtLayer(node) {
return node.type === 'atrule' && node.name === 'layer'
}

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

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

if (node.parent && node.parent.type !== 'root') {
if (node.parent && !(isRoot(node.parent) || isAtLayer(node.parent))) {
found = true
node.warn(
result,
Expand Down
25 changes: 25 additions & 0 deletions tests/detect-nesting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,31 @@ it('should warn when we detect nested css', () => {
})
})

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

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

return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
@layer tw-base, tw-components, tw-utilities;
@layer tw-utilities {
.underline {
text-decoration-line: underline;
}
}
`)
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