lib/sass/selector/simple.rb in sass-3.3.14 vs lib/sass/selector/simple.rb in sass-3.4.0.rc.1

- old
+ new

@@ -12,32 +12,22 @@ # or `nil` if it was not declared in a file (e.g. on stdin). # # @return [String, nil] attr_accessor :filename - # Returns a representation of the node as an array of strings and - # potentially {Sass::Script::Tree::Node}s (if there's interpolation in the - # selector). When the interpolation is resolved and the strings are joined - # together, this will be the string representation of this node. + # @see #to_s # - # @return [Array<String, Sass::Script::Tree::Node>] - def to_a - Sass::Util.abstract(self) - end - - # Returns a string representation of the node. - # This is basically the selector string. - # # @return [String] def inspect - to_a.map {|e| e.is_a?(Sass::Script::Tree::Node) ? "\#{#{e.to_sass}}" : e}.join + to_s end - # @see \{#inspect} + # Returns the selector string. + # # @return [String] def to_s - inspect + Sass::Util.abstract(self) end # Returns a hash code for this selector object. # # By default, this is based on the value of \{#to\_a}, @@ -56,11 +46,11 @@ # this should be overridden. # # @param other [Object] The object to test equality against # @return [Boolean] Whether or not this is equal to `other` def eql?(other) - other.class == self.class && other.hash == hash && other.equality_key.eql?(equality_key) + other.class == self.class && other.hash == hash && other.equality_key == equality_key end alias_method :==, :eql? # Unifies this selector with a {SimpleSequence}'s {SimpleSequence#members members array}, # returning another `SimpleSequence` members array @@ -81,29 +71,28 @@ # this exception will only ever be raised as a result of programmer error def unify(sels) return sels if sels.any? {|sel2| eql?(sel2)} sels_with_ix = Sass::Util.enum_with_index(sels) _, i = - if is_a?(Pseudo) || is_a?(SelectorPseudoClass) + if is_a?(Pseudo) sels_with_ix.find {|sel, _| sel.is_a?(Pseudo) && (sels.last.type == :element)} else - sels_with_ix.find {|sel, _| sel.is_a?(Pseudo) || sel.is_a?(SelectorPseudoClass)} + sels_with_ix.find {|sel, _| sel.is_a?(Pseudo)} end return sels + [self] unless i sels[0...i] + [self] + sels[i..-1] end protected # Returns the key used for testing whether selectors are equal. # - # This is based on \{#to\_a}, with adjacent strings merged so that - # selectors constructed in different ways are considered equivalent. + # This is a cached version of \{#to\_s}. # - # @return [Array<String, Sass::Script::Tree::Node>] + # @return [String] def equality_key - @equality_key ||= Sass::Util.merge_adjacent_strings(to_a) + @equality_key ||= to_s end # Unifies two namespaces, # returning a namespace that works for both of them if possible. # @@ -116,12 +105,12 @@ # 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.nil? || ns1 == '*' || ns2.nil? || ns2 == '*' + return ns2, true if ns1 == '*' + return ns1, true if ns2 == '*' [ns1 || ns2, true] end end end end