Ensure full node stays, if only a partial is used (#5617)

This commit is contained in:
Robin Malfait 2021-09-28 11:54:39 +02:00 • committed by GitHub
parent 6c0b8e8f0f
commit 5d6d84fda1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 92 additions and 2 deletions

View file

@ -59,11 +59,22 @@ function getClasses(selector) {
}
function extractCandidates(node) {
let classes = node.type === 'rule' ? getClasses(node.selector) : []
let classes = []
if (node.type === 'rule') {
for (let selector of node.selectors) {
let classCandidates = getClasses(selector)
// At least one of the selectors contains non-"on-demandable" candidates.
if (classCandidates.length === 0) return []
classes = [...classes, ...classCandidates]
}
return classes
}
if (node.type === 'atrule') {
node.walkRules((rule) => {
classes = [...classes, ...getClasses(rule.selector)]
classes = [...classes, ...rule.selectors.flatMap((selector) => getClasses(selector))]
})
}

View file

@ -0,0 +1,79 @@
import { run, html, css } from './util/run'
it('should generate the partial selector, if only a partial is used (base layer)', () => {
let config = {
content: [{ raw: html`<div></div>` }],
corePlugins: { preflight: false },
}
let input = css`
@tailwind base;
@layer base {
:root {
font-weight: bold;
}
/* --- */
:root,
.a {
color: black;
}
}
`
return run(input, config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
:root {
font-weight: bold;
}
/* --- */
:root,
.a {
color: black;
}
`)
})
})
it('should generate the partial selector, if only a partial is used (utilities layer)', () => {
let config = {
content: [{ raw: html`<div class="a"></div>` }],
corePlugins: { preflight: false },
}
let input = css`
@tailwind utilities;
@layer utilities {
:root {
font-weight: bold;
}
/* --- */
:root,
.a {
color: black;
}
}
`
return run(input, config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
:root {
font-weight: bold;
}
/* --- */
:root,
.a {
color: black;
}
`)
})
})