Skip to content

Commit

Permalink
fix: ::highlight(Name) formatted without Name (#113)
Browse files Browse the repository at this point in the history
closes #112
  • Loading branch information
bartveneman authored Dec 28, 2024
1 parent f55704c commit 96e5f3c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 3 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export function format(css, { minify = false } = {}) {
return buffer
}

/** @param {import('css-tree').Selector|import('css-tree').PseudoClassSelector} node */
/** @param {import('css-tree').Selector|import('css-tree').PseudoClassSelector|import('css-tree').PseudoElementSelector} node */
function print_simple_selector(node) {
let buffer = EMPTY_STRING
let children = node.children || []
Expand All @@ -183,19 +183,15 @@ export function format(css, { minify = false } = {}) {
}
break
}
case 'PseudoClassSelector':
case 'PseudoElementSelector': {
buffer += COLON + COLON
buffer += lowercase(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 print them as `::before` and `::after`
let pseudo = lowercase(child.name)

if (pseudo === 'before' || pseudo === 'after') {
if (pseudo === 'before' || pseudo === 'after' || child.type === 'PseudoElementSelector') {
buffer += COLON
}

Expand Down
8 changes: 8 additions & 0 deletions test/selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ li:nth-child() {}`
assert.equal(actual, expected)
})

test(`formats ::highlight and ::highlight(Name) correctly`, () => {
let actual = format(`::highlight,::highlight(Name),::highlight(my-thing) {}`)
let expected = `::highlight,
::highlight(Name),
::highlight(my-thing) {}`
assert.equal(actual, expected)
})

test('formats unknown pseudos correctly', () => {
let actual = format(`
::foo-bar,
Expand Down

0 comments on commit 96e5f3c

Please sign in to comment.