Skip to content

Commit 2b2c509

Browse files
authored
Merge pull request tailwindlabs#1053 from tailwindcss/dont-generate-variants-for-nested-rules
Don't mutate nested rules when generating variants
2 parents 27a9cd9 + 660ea44 commit 2b2c509

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

__tests__/variantsAtRule.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,43 @@ test('the default variant can be generated in a specified position', () => {
393393
})
394394
})
395395

396+
test('nested rules are not modified', () => {
397+
const input = `
398+
@variants focus, active, hover {
399+
.banana {
400+
color: yellow;
401+
.chocolate { color: brown; }
402+
}
403+
}
404+
`
405+
406+
const output = `
407+
.banana {
408+
color: yellow;
409+
.chocolate { color: brown; }
410+
}
411+
.focus\\:banana:focus {
412+
color: yellow;
413+
.chocolate { color: brown; }
414+
}
415+
.active\\:banana:active {
416+
color: yellow;
417+
.chocolate { color: brown; }
418+
}
419+
.hover\\:banana:hover {
420+
color: yellow;
421+
.chocolate { color: brown; }
422+
}
423+
`
424+
425+
return run(input, {
426+
...config,
427+
}).then(result => {
428+
expect(result.css).toMatchCss(output)
429+
expect(result.warnings().length).toBe(0)
430+
})
431+
})
432+
396433
test('plugin variants can modify rules using the raw PostCSS API', () => {
397434
const input = `
398435
@variants important {

src/util/generateVariantFunction.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ export default function generateVariantFunction(generator) {
1212
container: cloned,
1313
separator: config.separator,
1414
modifySelectors: modifierFunction => {
15-
cloned.walkRules(rule => {
15+
cloned.each(rule => {
16+
if (rule.type !== 'rule') {
17+
return
18+
}
19+
1620
rule.selectors = rule.selectors.map(selector => {
1721
const className = selectorParser(selectors => {
1822
return selectors.first.filter(({ type }) => type === 'class').pop().value

0 commit comments

Comments
 (0)