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
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,15 @@ function print_simple_selector(node, css) {
break
}
case 'PseudoClassSelector': {
buffer += ':' + child.name
buffer += ':'

// 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') {
buffer += ':'
}

buffer += child.name

if (child.children) {
buffer += '(' + print_simple_selector(child, css) + ')'
Expand Down
18 changes: 18 additions & 0 deletions test/selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ test("formats nested selector combinators", () => {
}
})

test('formats pseudo selectors', () => {
let css = `
a::before,
a::after,
b:before,
b:after,
c::first-letter {}
`
let expected = `a::before,
a::after,
b::before,
b::after,
c::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