Skip to content

Commit e5ed08b

Browse files
Handle duplicate atrules without children (#8122)
* Handle duplicate atrules without children We assumed that all At Rule nodes had children. Including ones that do not and should not — for example `@import url(…);`. Since this is not the case we’ll skip adding children for nodes that don’t have any. * Update changelog Co-authored-by: Jordi Marimon Palarea <jordimarimon7@gmail.com>
1 parent 5c76de7 commit e5ed08b

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Types: allow for arbitrary theme values (for 3rd party plugins) ([#7926](https://github.com/tailwindlabs/tailwindcss/pull/7926))
1313
- Don’t split vars with numbers in them inside arbitrary values ([#8091](https://github.com/tailwindlabs/tailwindcss/pull/8091))
1414
- Require matching prefix when detecting negatives ([#8121](https://github.com/tailwindlabs/tailwindcss/pull/8121))
15+
- Handle duplicate At Rules without children ([#8122](https://github.com/tailwindlabs/tailwindcss/pull/8122))
1516

1617
### Added
1718

src/lib/collapseAdjacentRules.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ export default function collapseAdjacentRules() {
2929
(currentRule[property] ?? '').replace(/\s+/g, ' ')
3030
)
3131
) {
32-
currentRule.append(node.nodes)
32+
// An AtRule may not have children (for example if we encounter duplicate @import url(…) rules)
33+
if (node.nodes) {
34+
currentRule.append(node.nodes)
35+
}
36+
3337
node.remove()
3438
} else {
3539
currentRule = node

tests/collapse-adjacent-rules.test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs'
22
import path from 'path'
33

4-
import { run, css } from './util/run'
4+
import { run, html, css } from './util/run'
55

66
test('collapse adjacent rules', () => {
77
let config = {
@@ -61,3 +61,21 @@ test('collapse adjacent rules', () => {
6161
expect(result.css).toMatchFormattedCss(expected)
6262
})
6363
})
64+
65+
test('duplicate url imports does not break rule collapsing', () => {
66+
let config = {
67+
content: [{ raw: html`` }],
68+
corePlugins: { preflight: false },
69+
}
70+
71+
let input = css`
72+
@import url('https://example.com');
73+
@import url('https://example.com');
74+
`
75+
76+
return run(input, config).then((result) => {
77+
expect(result.css).toMatchFormattedCss(css`
78+
@import url('https://example.com');
79+
`)
80+
})
81+
})

0 commit comments

Comments
 (0)