Skip to content

refactor: Improve how whitespace is consumed in complex selectors #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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
9 changes: 5 additions & 4 deletions lib/syntax_tree/css/selectors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,14 @@ def complex_selector
child_nodes = [compound_selector]

loop do
maybe { consume_whitespace }

if (c = maybe { combinator })
child_nodes << c

maybe { consume_whitespace }
end

if (s = maybe { compound_selector })
child_nodes << s
else
Expand All @@ -363,8 +368,6 @@ def relative_selector
# <compound-selector> = [ <type-selector>? <subclass-selector>*
# [ <pseudo-element-selector> <pseudo-class-selector>* ]* ]!
def compound_selector
consume_whitespace

type = maybe { type_selector }
subclasses = []

Expand Down Expand Up @@ -401,8 +404,6 @@ def simple_selector

# <combinator> = '>' | '+' | '~' | [ '|' '|' ]
def combinator
consume_whitespace

value =
options do
maybe { consume(">") } ||
Expand Down