lib/sass/selector/simple.rb in sass-3.7.4 vs lib/sass/selector/simple.rb in sass-4.0.0.alpha.1

- old
+ new

@@ -3,11 +3,11 @@ # The abstract superclass for simple selectors # (that is, those that don't compose multiple selectors). class Simple # The line of the Sass template on which this selector was declared. # - # @return [Integer] + # @return [Fixnum] attr_accessor :line # The name of the file in which this selector was declared, # or `nil` if it was not declared in a file (e.g. on stdin). # @@ -29,24 +29,22 @@ to_s end # Returns the selector string. # - # @param opts [Hash] rendering options. - # @option opts [Symbol] :style The css rendering style. # @return [String] - def to_s(opts = {}) + def to_s Sass::Util.abstract(self) end # Returns a hash code for this selector object. # # By default, this is based on the value of \{#to\_a}, # so if that contains information irrelevant to the identity of the selector, # this should be overridden. # - # @return [Integer] + # @return [Fixnum] def hash @_hash ||= equality_key.hash end # Checks equality between this and another object. @@ -78,14 +76,14 @@ # such as {Parent} or {Interpolation}, is used in unification. # Since these selectors should be resolved # by the time extension and unification happen, # this exception will only ever be raised as a result of programmer error def unify(sels) - return sels.first.unify([self]) if sels.length == 1 && sels.first.is_a?(Universal) return sels if sels.any? {|sel2| eql?(sel2)} + sels_with_ix = Sass::Util.enum_with_index(sels) if !is_a?(Pseudo) || (sels.last.is_a?(Pseudo) && sels.last.type == :element) - _, i = sels.each_with_index.find {|sel, _| sel.is_a?(Pseudo)} + _, i = sels_with_ix.find {|sel, _| sel.is_a?(Pseudo)} end return sels + [self] unless i sels[0...i] + [self] + sels[i..-1] end @@ -112,13 +110,13 @@ # The first value is the unified namespace, or `nil` for no namespace. # The second value is whether or not a namespace that works for both inputs # could be found at all. # If the second value is `false`, the first should be ignored. def unify_namespaces(ns1, ns2) + return nil, false unless ns1 == ns2 || ns1.nil? || ns1 == '*' || ns2.nil? || ns2 == '*' return ns2, true if ns1 == '*' return ns1, true if ns2 == '*' - return nil, false unless ns1 == ns2 - [ns1, true] + [ns1 || ns2, true] end end end end