Skip to content
Browse files

Fixes #879 Extends with parent reference

  • Loading branch information...
1 parent b2944cc commit b0808e888050b44f48deb3773e99696d1db0b005 @tonistiigi committed Nov 20, 2012
Showing with 36 additions and 11 deletions.
  1. +16 −11 lib/visitor/compiler.js
  2. +8 −0 test/cases/extend.with.parent.reference.css
  3. +12 −0 test/cases/extend.with.parent.reference.styl
View
27 lib/visitor/compiler.js
@@ -454,6 +454,20 @@ Compiler.prototype.compileSelectors = function(arr){
, selectors = []
, buf = [];
+ function interpolateParent(selector, buf) {
+ var str = selector.val.trim();
+ if (buf.length) {
+ for (var i = 0, len = buf.length; i < len; ++i) {
+ if (~buf[i].indexOf('&')) {
+ str = buf[i].replace(/&/g, str).trim();
+ } else {
+ str += ' ' + buf[i].trim();
+ }
+ }
+ }
+ return str;
+ }
+
function compile(arr, i) {
if (i) {
arr[i].forEach(function(selector){
@@ -462,21 +476,12 @@ Compiler.prototype.compileSelectors = function(arr){
compile(arr, i - 1);
buf.shift();
} else {
- selectors.push(selector.val);
+ selectors.push(interpolateParent(selector, buf));
}
});
} else {
arr[0].forEach(function(selector){
- var str = selector.val.trim();
- if (buf.length) {
- for (var i = 0, len = buf.length; i < len; ++i) {
- if (~buf[i].indexOf('&')) {
- str = buf[i].replace(/&/g, str).trim();
- } else {
- str += ' ' + buf[i].trim();
- }
- }
- }
+ var str = interpolateParent(selector, buf);
selectors.push(self.indent + str.trimRight());
});
}
View
8 test/cases/extend.with.parent.reference.css
@@ -0,0 +1,8 @@
+#button_a:hover,
+#button_b:hover {
+ color: #fff;
+}
+body #button_c:hover,
+body #button_d:hover {
+ color: #000;
+}
View
12 test/cases/extend.with.parent.reference.styl
@@ -0,0 +1,12 @@
+#button_a
+ &:hover
+ color #fff
+#button_b
+ @extend #button_a
+
+body
+ #button_c
+ &:hover
+ color #000
+ #button_d
+ @extend body #button_c

0 comments on commit b0808e8

Please sign in to comment.
Something went wrong with that request. Please try again.