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

Add support for PostCSS Document nodes #7291

Merged
merged 2 commits into from Feb 25, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Allow default ring color to be a function ([#7587](https://github.com/tailwindlabs/tailwindcss/pull/7587))
- Add `rgb` and `hsl` color helpers for CSS variables ([#7665](https://github.com/tailwindlabs/tailwindcss/pull/7665))
- Support PostCSS `Document` nodes ([#7291](https://github.com/tailwindlabs/tailwindcss/pull/7291))

## [3.0.23] - 2022-02-16

Expand Down
16 changes: 15 additions & 1 deletion src/index.js
Expand Up @@ -13,7 +13,21 @@ module.exports = function tailwindcss(configOrPath) {
return root
},
function (root, result) {
processTailwindFeatures(setupTrackingContext(configOrPath))(root, result)
let context = setupTrackingContext(configOrPath)

if (root.type === 'document') {
let roots = root.nodes.filter((node) => node.type === 'root')

for (const root of roots) {
if (root.type === 'root') {
processTailwindFeatures(context)(root, result)
}
}

return
}

processTailwindFeatures(context)(root, result)
},
env.DEBUG &&
function (root) {
Expand Down
35 changes: 35 additions & 0 deletions tests/variants.test.js
@@ -1,5 +1,6 @@
import fs from 'fs'
import path from 'path'
import postcss from 'postcss'

import { run, css, html, defaults } from './util/run'

Expand Down Expand Up @@ -568,3 +569,37 @@ test('The visited variant removes opacity support', () => {
`)
})
})

it('appends variants to the correct place when using postcss documents', () => {
let config = {
content: [{ raw: html`<div class="underline sm:underline"></div>` }],
plugins: [],
corePlugins: { preflight: false },
}

const doc = postcss.document()
doc.append(postcss.parse(`a {}`))
doc.append(postcss.parse(`@tailwind base`))
doc.append(postcss.parse(`@tailwind utilities`))
doc.append(postcss.parse(`b {}`))

const result = doc.toResult()

return run(result, config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
a {
}
${defaults}
.underline {
text-decoration-line: underline;
}
@media (min-width: 640px) {
.sm\:underline {
text-decoration-line: underline;
}
}
b {
}
`)
})
})