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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"knip": "knip"
},
"dependencies": {
"@projectwallace/css-parser": "^0.19.6"
"@projectwallace/css-parser": "^0.19.9"
},
"devDependencies": {
"@projectwallace/preset-oxlint": "^0.0.11",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
is_url,
is_string,
is_operator,
is_identifier,
is_raw,
is_selector_list,
is_type_selector,
Expand Down Expand Up @@ -401,6 +402,11 @@ function print_selector_argument(node: CSSNode, optional_space = SPACE): string
return print_string(node.name ?? EMPTY_STRING)
}

// Non-selector pseudo-class arguments, e.g. `:unknown(foo.bar)`
if (is_identifier(node)) {
return node.text
}

return print_selector(node as Selector, optional_space)
}

Expand All @@ -415,6 +421,10 @@ function print_selector_list(
): string {
let parts: string[] = []
node.for_each((child) => {
if (is_operator(child)) {
// Commas between arguments are emitted below
return
}
if (is_selector_list(child)) {
parts.push(print_selector_list(child, optional_space))
} else {
Expand Down
25 changes: 24 additions & 1 deletion test/selectors.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from 'vitest'
import { format } from '../src/lib/index.js'
import { format, minify } from '../src/lib/index.js'

test('A single selector is rendered without a trailing comma', () => {
let actual = format('a {}')
Expand Down Expand Up @@ -292,3 +292,26 @@ test('whitespace before a comma does not leave a trailing combinator', () => {
let expected = 'a > b,\nc {}'
expect(actual).toEqual(expected)
})

test('formats :lang() with multiple identifiers', () => {
let actual = format(`:lang(en,nl),a:lang(en-US , nl){}`)
let expected = `:lang("en", "nl"),
a:lang("en-US", "nl") {}`
expect(actual).toEqual(expected)
})

test('formats single-argument :lang()', () => {
expect(format(`:lang(en){}`)).toEqual(`:lang("en") {}`)
})

test('formats unknown pseudo with a single identifier argument', () => {
expect(format(`:unknown(foo.bar){}`)).toEqual(`:unknown(foo.bar) {}`)
})

test('minifies :lang() with multiple arguments', () => {
expect(minify(`:lang(en, nl) { color: red }`)).toEqual(`:lang("en","nl"){color:red}`)
})

test('minifies unknown pseudo with multiple arguments', () => {
expect(minify(`:unknown(a.b, c) {}`)).toEqual(`:unknown(a.b,c){}`)
})
Loading