Skip to content

Commit c689a6c

Browse files
committed
Format pseudo-class functions with complex arguments
1 parent 5b4571f commit c689a6c

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

lib/syntax_tree/css/format.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ def visit_pseudo_class_selector(node)
100100
node.value.format(q)
101101
end
102102

103+
# Visit a Selectors::PseudoClassFunction node.
104+
def visit_pseudo_class_function(node)
105+
q.text(node.name)
106+
q.text("(")
107+
q.seplist(node.arguments, -> { q.text(", ") }) do |selector|
108+
selector.format(q)
109+
end
110+
q.text(")")
111+
end
112+
103113
# Visit a Selectors::PseudoElementSelector node.
104114
def visit_pseudo_element_selector(node)
105115
q.text(":")
@@ -127,7 +137,6 @@ def visit_compound_selector(node)
127137
node.child_nodes.each do |node_|
128138
node_.format(q)
129139
end
130-
# TODO: pseudo-elements
131140
end
132141
end
133142

lib/syntax_tree/css/pretty_print.rb

+15-3
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,19 @@ def visit_pseudo_class_function(node)
380380
q.breakable
381381
q.pp(node.name)
382382

383+
q.breakable
384+
q.text("(arguments")
385+
383386
if node.arguments.any?
384-
q.breakable
385-
q.seplist(node.arguments) { |argument| q.pp(argument) }
387+
q.nest(2) do
388+
q.breakable
389+
q.seplist(node.arguments) { |argument| q.pp(argument) }
390+
end
391+
392+
q.breakable("")
386393
end
394+
395+
q.text(")")
387396
end
388397
end
389398

@@ -443,7 +452,10 @@ def visit_complex_selector(node)
443452
def visit_compound_selector(node)
444453
token("compound-selector") do
445454
q.breakable
446-
q.pp(node.type)
455+
token("type") do
456+
q.breakable
457+
q.pp(node.type)
458+
end
447459

448460
q.breakable
449461
q.text("(subclasses")

test/selectors_test.rb

+7
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ class SelectorsTest < Minitest::Spec
253253
)
254254
end
255255

256+
it "with a pseudo-class function" do
257+
assert_selector_format(
258+
".flex:not(div, span.wide, .hidden)",
259+
".flex:not(div, span.wide, .hidden)",
260+
)
261+
end
262+
256263
it "with class selectors" do
257264
assert_selector_format(
258265
"div.flex.text-xl",

0 commit comments

Comments
 (0)