Skip to content

Commit

Permalink
Undesired spaces with partial reference selector using ranges. Fixes s…
Browse files Browse the repository at this point in the history
  • Loading branch information
Panya authored and kizu committed Mar 5, 2016
1 parent e4ca920 commit 2bd852e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/selector-parser.js
Expand Up @@ -190,7 +190,9 @@ SelectorParser.prototype.number = function() {

SelectorParser.prototype.range = function() {
var start = this.number()
, parsed
, ret;

if ('..' == this.str.slice(0, 2)) {
this.skip(2);
var end = this.number()
Expand All @@ -206,11 +208,17 @@ SelectorParser.prototype.range = function() {
}

if (end < len - 1) {
ret = this.parts.slice(start, end + 1).map(function(part) {
parsed = this.parts.slice(start, end + 1).map(function(part) {
var selector = new SelectorParser(part, this.stack, this.parts);
selector.raw = true;
return selector.parse().val.trim();
}, this).join(' ');
return selector.parse();
}, this);

ret = parsed.map(function(selector) {
return selector.val.trim();
}).join(parsed.every(function(selector) {
return selector.nested;
}) ? ' ' : '');
}
} else {
ret = this.stack[
Expand Down
6 changes: 6 additions & 0 deletions test/cases/selector.reference.css
Expand Up @@ -105,3 +105,9 @@ foo /deep/ /deep/ {
test: '.foo';
test: '.baz ~/';
}
.s1-s2-s3 {
syntax: "^[2]";
}
.s1-s2-s3 {
syntax: "^[0..2]";
}
11 changes: 11 additions & 0 deletions test/cases/selector.reference.styl
Expand Up @@ -127,3 +127,14 @@ foo /deep/
~/
test: selector('~/')
test: selector('.baz ~/')

.s1
&-s2
&-s3
&-s4
^[2]
// first three levels of selectors
syntax: "^[2]"
^[0..2]
// I expect this to be identical to the above, but it's not
syntax: "^[0..2]"

0 comments on commit 2bd852e

Please sign in to comment.