Permalink
Browse files

Properly determine equality of selectors created with &-foo.

Closes #1148
  • Loading branch information...
1 parent caa3645 commit 12849a02b58577b80767b43110db3643ec78760a @nex3 nex3 committed Mar 7, 2014
Showing with 22 additions and 2 deletions.
  1. +12 −2 lib/sass/selector/simple.rb
  2. +10 −0 test/sass/extend_test.rb
@@ -46,7 +46,7 @@ def to_s
#
# @return [Fixnum]
def hash
- @_hash ||= to_a.hash
+ @_hash ||= equality_key.hash
end
# Checks equality between this and another object.
@@ -58,7 +58,7 @@ def hash
# @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.to_a.eql?(to_a)
+ other.class == self.class && other.hash == hash && other.equality_key.eql?(equality_key)
end
alias_method :==, :eql?
@@ -94,6 +94,16 @@ def unify(sels)
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.
+ #
+ # @return [Array<String, Sass::Script::Tree::Node>]
+ def equality_key
+ @equality_key ||= Sass::Util.merge_adjacent_strings(to_a)
+ end
+
# Unifies two namespaces,
# returning a namespace that works for both of them if possible.
#
View
@@ -1115,6 +1115,16 @@ def test_optional_extend_succeeds_when_extension_fails
# Regression Tests
+ def test_extend_parent_selector_suffix
+ assert_equal <<CSS, render(<<SCSS)
+.a-b, .c {
+ x: y; }
+CSS
+.a {&-b {x: y}}
+.c {@extend .a-b}
+SCSS
+ end
+
def test_pseudo_element_superselector
# Pseudo-elements shouldn't be removed in superselector calculations.
assert_equal <<CSS, render(<<SCSS)

0 comments on commit 12849a0

Please sign in to comment.