This commit is contained in:
Luke Page
2014-02-01 18:18:03 +00:00

View File

@@ -32,33 +32,59 @@ tree.Selector.prototype = {
match: function (other) {
var elements = this.elements,
len = elements.length,
oelements, olen, i;
oelements = other.elements.map( function(v) {
return v.combinator.value + (v.value.value || v.value);
}).join("").match(/[,&#\.\w-]([\w-]|(\\.))*/g);
// ^ regexp could be more simple but see test/less/css-escapes.less:17, doh!
if (!oelements) {
return 0;
}
olen, i;
if (oelements[0] === "&") {
oelements.shift();
}
other.CacheElements();
olen = oelements.length;
olen = other._elements.length;
if (olen === 0 || len < olen) {
return 0;
} else {
for (i = 0; i < olen; i++) {
if (elements[i].value !== oelements[i]) {
if (elements[i].value !== other._elements[i]) {
return 0;
}
}
}
return olen; // return number of matched elements
},
CacheElements: function(){
var css = '', len, v, i;
if( !this._elements ){
len = this.elements.length;
for(i = 0; i < len; i++){
v = this.elements[i];
css += v.combinator.value;
if( !v.value.value ){
css += v.value;
continue;
}
if( typeof v.value.value !== "string" ){
css = '';
break;
}
css += v.value.value;
}
this._elements = css.match(/[,&#\.\w-]([\w-]|(\\.))*/g);
if (this._elements) {
if (this._elements[0] === "&") {
this._elements.shift();
}
}else{
this._elements = [];
}
}
},
eval: function (env) {
var evaldCondition = this.condition && this.condition.eval(env),
elements = this.elements, extendList = this.extendList;