lib/sass/selector/pseudo.rb in sass-3.5.0.pre.rc.1 vs lib/sass/selector/pseudo.rb in sass-3.5.0
- old
+ new
@@ -1,5 +1,6 @@
+# coding: utf-8
module Sass
module Selector
# A pseudoclass (e.g. `:visited`) or pseudoelement (e.g. `::first-line`)
# selector. It can have arguments (e.g. `:nth-child(2n+1)`) which can
# contain selectors (e.g. `:nth-child(2n+1 of .foo)`).
@@ -50,10 +51,18 @@
def unique?
type == :class && normalized_name == 'root'
end
+ # Whether or not this selector should be hidden due to containing a
+ # placeholder.
+ def invisible?
+ # :not() is a special caseāif you eliminate all the placeholders from
+ # it, it should match anything.
+ name != 'not' && @selector && @selector.members.all? {|s| s.invisible?}
+ end
+
# Returns a copy of this with \{#selector} set to \{#new\_selector}.
#
# @param new_selector [CommaSequence]
# @return [Array<Simple>]
def with_selector(new_selector)
@@ -79,11 +88,11 @@
# As above, we could theoretically support :not within :matches, but
# doing so would require this method and its callers to handle much
# more complex cases that likely aren't worth the pain.
next [] unless sel.name == name && sel.arg == arg
sel.selector.members
- when 'has', 'host', 'host-context'
+ when 'has', 'host', 'host-context', 'slotted'
# We can't expand nested selectors here, because each layer adds an
# additional layer of semantics. For example, `:has(:has(img))`
# doesn't match `<div><img></div>` but `:has(img)` does.
sel
else
@@ -116,10 +125,14 @@
@normalized_name ||= name.gsub(/^-[a-zA-Z0-9]+-/, '')
end
# @see Selector#to_s
def to_s(opts = {})
+ # :not() is a special case, because :not(<nothing>) should match
+ # everything.
+ return '' if name == 'not' && @selector && @selector.members.all? {|m| m.invisible?}
+
res = (syntactic_type == :class ? ":" : "::") + @name
if @arg || @selector
res << "("
res << @arg.strip if @arg
res << " " if @arg && @selector
@@ -163,10 +176,10 @@
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'
+ when 'has', 'host', 'host-context', 'slotted'
# Like :matches, :has (et al) can be a superselector of another
# selector if its constituent selectors are a superset of those of
# another :has in the other selector. However, the :matches other case
# doesn't work, because :has refers to nested elements.
(their_sseq.selector_pseudo_classes[normalized_name] || []).any? do |their_sel|