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

Handle duplicate atrules without children #8122

Merged
merged 2 commits into from Apr 15, 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 @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Types: allow for arbitrary theme values (for 3rd party plugins) ([#7926](https://github.com/tailwindlabs/tailwindcss/pull/7926))
- Don’t split vars with numbers in them inside arbitrary values ([#8091](https://github.com/tailwindlabs/tailwindcss/pull/8091))
- Require matching prefix when detecting negatives ([#8121](https://github.com/tailwindlabs/tailwindcss/pull/8121))
- Handle duplicate At Rules without children ([#8122](https://github.com/tailwindlabs/tailwindcss/pull/8122))

### Added

Expand Down
6 changes: 5 additions & 1 deletion src/lib/collapseAdjacentRules.js
Expand Up @@ -29,7 +29,11 @@ export default function collapseAdjacentRules() {
(currentRule[property] ?? '').replace(/\s+/g, ' ')
)
) {
currentRule.append(node.nodes)
// An AtRule may not have children (for example if we encounter duplicate @import url(…) rules)
if (node.nodes) {
currentRule.append(node.nodes)
}

node.remove()
} else {
currentRule = node
Expand Down
20 changes: 19 additions & 1 deletion tests/collapse-adjacent-rules.test.js
@@ -1,7 +1,7 @@
import fs from 'fs'
import path from 'path'

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

test('collapse adjacent rules', () => {
let config = {
Expand Down Expand Up @@ -61,3 +61,21 @@ test('collapse adjacent rules', () => {
expect(result.css).toMatchFormattedCss(expected)
})
})

test('duplicate url imports does not break rule collapsing', () => {
let config = {
content: [{ raw: html`` }],
corePlugins: { preflight: false },
}

let input = css`
@import url('https://example.com');
@import url('https://example.com');
`

return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
@import url('https://example.com');
`)
})
})