Skip to content

Commit 96e5f3c

Browse files
authored
fix: ::highlight(Name) formatted without Name (#113)
closes #112
1 parent f55704c commit 96e5f3c

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export function format(css, { minify = false } = {}) {
163163
return buffer
164164
}
165165

166-
/** @param {import('css-tree').Selector|import('css-tree').PseudoClassSelector} node */
166+
/** @param {import('css-tree').Selector|import('css-tree').PseudoClassSelector|import('css-tree').PseudoElementSelector} node */
167167
function print_simple_selector(node) {
168168
let buffer = EMPTY_STRING
169169
let children = node.children || []
@@ -183,19 +183,15 @@ export function format(css, { minify = false } = {}) {
183183
}
184184
break
185185
}
186+
case 'PseudoClassSelector':
186187
case 'PseudoElementSelector': {
187-
buffer += COLON + COLON
188-
buffer += lowercase(child.name)
189-
break
190-
}
191-
case 'PseudoClassSelector': {
192188
buffer += COLON
193189

194190
// Special case for `:before` and `:after` which were used in CSS2 and are usually minified
195191
// as `:before` and `:after`, but we want to print them as `::before` and `::after`
196192
let pseudo = lowercase(child.name)
197193

198-
if (pseudo === 'before' || pseudo === 'after') {
194+
if (pseudo === 'before' || pseudo === 'after' || child.type === 'PseudoElementSelector') {
199195
buffer += COLON
200196
}
201197

test/selectors.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ li:nth-child() {}`
180180
assert.equal(actual, expected)
181181
})
182182

183+
test(`formats ::highlight and ::highlight(Name) correctly`, () => {
184+
let actual = format(`::highlight,::highlight(Name),::highlight(my-thing) {}`)
185+
let expected = `::highlight,
186+
::highlight(Name),
187+
::highlight(my-thing) {}`
188+
assert.equal(actual, expected)
189+
})
190+
183191
test('formats unknown pseudos correctly', () => {
184192
let actual = format(`
185193
::foo-bar,

0 commit comments

Comments
 (0)