def superselector?(their_sseq, parents = [])
case normalized_name
when 'matches', 'any'
(their_sseq.selector_pseudo_classes[normalized_name] || []).any? do |their_sel|
next false unless their_sel.is_a?(Pseudo)
next false unless their_sel.name == name
selector.superselector?(their_sel.selector)
end || selector.members.any? do |our_seq|
their_seq = Sequence.new(parents + [their_sseq])
our_seq.superselector?(their_seq)
end
when 'has', 'host', 'host-context'
(their_sseq.selector_pseudo_classes[normalized_name] || []).any? do |their_sel|
next false unless their_sel.is_a?(Pseudo)
next false unless their_sel.name == name
selector.superselector?(their_sel.selector)
end
when 'not'
selector.members.all? do |our_seq|
their_sseq.members.any? do |their_sel|
if their_sel.is_a?(Element) || their_sel.is_a?(Id)
our_sseq = our_seq.members.last
next false unless our_sseq.is_a?(SimpleSequence)
our_sseq.members.any? do |our_sel|
our_sel.class == their_sel.class && our_sel != their_sel
end
else
next false unless their_sel.is_a?(Pseudo)
next false unless their_sel.name == name
their_sel.selector.superselector?(CommaSequence.new([our_seq]))
end
end
end
when 'current'
(their_sseq.selector_pseudo_classes['current'] || []).any? do |their_current|
next false if their_current.name != name
selector == their_current.selector
end
when 'nth-child', 'nth-last-child'
their_sseq.members.any? do |their_sel|
next false unless their_sel.is_a?(Pseudo)
next false unless their_sel.name == name
next false unless their_sel.arg == arg
selector.superselector?(their_sel.selector)
end
else
throw "[BUG] Unknown selector pseudo class #{name}"
end
end