-
Notifications
You must be signed in to change notification settings - Fork 112
Fix selector splitting inside functional pseudo-classes #184
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -684,17 +684,45 @@ def unmatched_open_parenthesis?(declarations) | |||||||
| (lparen_index = declarations.index(LPAREN)) && !declarations.index(RPAREN, lparen_index) | ||||||||
| end | ||||||||
|
|
||||||||
| #-- | ||||||||
| # TODO: way too simplistic | ||||||||
| #++ | ||||||||
| # Split selector string on commas, but not commas inside parentheses | ||||||||
| # (e.g. :is(rect, circle) or :where(.a, .b) should not be split). | ||||||||
| def parse_selectors!(selectors) # :nodoc: | ||||||||
| @selectors = selectors.split(',').map do |s| | ||||||||
| @selectors = split_selectors(selectors).map do |s| | ||||||||
| s.gsub!(/\s+/, ' ') | ||||||||
| s.strip! | ||||||||
| s | ||||||||
| end | ||||||||
| end | ||||||||
|
|
||||||||
| def split_selectors(selectors) | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should add this to stay fast:
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... actually how about that performed the same (within 1%) and looks simpler to me
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call - I've spent some more time looking at performance and persuaded Claude to try a CSS selector aware scan, which seems to be only marginally less performant than .split(',') on newer rubies, especially with YJIT enabled. |
||||||||
| result = [] | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe call this selectors and the arg selector |
||||||||
| current = +'' | ||||||||
| depth = 0 | ||||||||
|
|
||||||||
| selectors.each_char do |char| | ||||||||
| case char | ||||||||
| when '(' | ||||||||
| depth += 1 | ||||||||
| current << char | ||||||||
| when ')' | ||||||||
| depth -= 1 | ||||||||
| current << char | ||||||||
| when ',' | ||||||||
| if depth > 0 | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would flip conditional to |
||||||||
| current << char | ||||||||
| else | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| result << current | ||||||||
| current = +'' | ||||||||
| end | ||||||||
| else | ||||||||
| current << char | ||||||||
| end | ||||||||
| end | ||||||||
|
|
||||||||
| result << current unless current.empty? | ||||||||
| result | ||||||||
| end | ||||||||
|
|
||||||||
| def split_value_preserving_function_whitespace(value) | ||||||||
| split_value = value.gsub(RE_FUNCTIONS) do |c| | ||||||||
| c.gsub!(/\s+/, WHITESPACE_REPLACEMENT) | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment belongs to split_selectors