mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
Don't mutate nested rules when generating variants
This commit is contained in:
parent
27a9cd9456
commit
660ea44db2
@ -393,6 +393,43 @@ test('the default variant can be generated in a specified position', () => {
|
||||
})
|
||||
})
|
||||
|
||||
test('nested rules are not modified', () => {
|
||||
const input = `
|
||||
@variants focus, active, hover {
|
||||
.banana {
|
||||
color: yellow;
|
||||
.chocolate { color: brown; }
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const output = `
|
||||
.banana {
|
||||
color: yellow;
|
||||
.chocolate { color: brown; }
|
||||
}
|
||||
.focus\\:banana:focus {
|
||||
color: yellow;
|
||||
.chocolate { color: brown; }
|
||||
}
|
||||
.active\\:banana:active {
|
||||
color: yellow;
|
||||
.chocolate { color: brown; }
|
||||
}
|
||||
.hover\\:banana:hover {
|
||||
color: yellow;
|
||||
.chocolate { color: brown; }
|
||||
}
|
||||
`
|
||||
|
||||
return run(input, {
|
||||
...config,
|
||||
}).then(result => {
|
||||
expect(result.css).toMatchCss(output)
|
||||
expect(result.warnings().length).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
test('plugin variants can modify rules using the raw PostCSS API', () => {
|
||||
const input = `
|
||||
@variants important {
|
||||
|
||||
@ -12,7 +12,11 @@ export default function generateVariantFunction(generator) {
|
||||
container: cloned,
|
||||
separator: config.separator,
|
||||
modifySelectors: modifierFunction => {
|
||||
cloned.walkRules(rule => {
|
||||
cloned.each(rule => {
|
||||
if (rule.type !== 'rule') {
|
||||
return
|
||||
}
|
||||
|
||||
rule.selectors = rule.selectors.map(selector => {
|
||||
const className = selectorParser(selectors => {
|
||||
return selectors.first.filter(({ type }) => type === 'class').pop().value
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user