Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,24 @@ function print_simple_selector(node, css) {
}
break
}
case 'PseudoElementSelector': {
buffer += COLON + COLON
buffer += is_uppercase(child.name) ? child.name.toLowerCase() : child.name
break
}
case 'PseudoClassSelector': {
buffer += COLON

// Special case for `:before` and `:after` which were used in CSS2 and are usually minified
// as `:before` and `:after`, but we want to keep them as `::before` and `::after`
if (child.name === 'before' || child.name === 'after') {
let name = child.name
let pseudo = is_uppercase(name) ? name.toLowerCase() : name

if (pseudo === 'before' || pseudo === 'after') {
buffer += COLON
}

buffer += child.name
buffer += pseudo

if (child.children) {
buffer += '(' + print_simple_selector(child, css) + ')'
Expand Down
20 changes: 20 additions & 0 deletions test/selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@ c::first-letter {}`
assert.equal(actual, expected)
})

test('formats pseudo elements with odd casing', () => {
let css = `
a::Before,
a::After,
b:Before,
b:After,
c:After,
d::First-letter {}
`
let expected = `a::before,
a::after,
b::before,
b::after,
c::after,
d::first-letter {}`

let actual = format(css)
assert.equal(actual, expected)
})

test("formats selectors with Nth", () => {
let fixtures = [
[`li:nth-child(3n-2) {}`, `li:nth-child(3n -2) {}`],
Expand Down