From a51c8480efaf12d8071a5f5192770aa13cf3cc70 Mon Sep 17 00:00:00 2001 From: seven-phases-max Date: Sat, 4 Oct 2014 20:19:50 +0400 Subject: [PATCH] Fix interpolated selector match regression --- lib/less/tree/selector.js | 46 +++++++++--------------------- test/css/mixins-interpolated.css | 4 +++ test/less/mixins-interpolated.less | 6 ++++ 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/lib/less/tree/selector.js b/lib/less/tree/selector.js index e27e70f01..993d23709 100644 --- a/lib/less/tree/selector.js +++ b/lib/less/tree/selector.js @@ -50,41 +50,23 @@ Selector.prototype.match = function (other) { return olen; // return number of matched elements }; -Selector.prototype.CacheElements = function(){ - var css = '', len, v, i; +Selector.prototype.CacheElements = function() { + if (this._elements) + return; + + var elements = this.elements.map( function(v) { + return v.combinator.value + (v.value.value || v.value); + }).join("").match(/[,&#\*\.\w-]([\w-]|(\\.))*/g); - 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; + if (elements) { + if (elements[0] === "&") { + elements.shift(); } - - this._elements = css.match(/[,&#\*\.\w-]([\w-]|(\\.))*/g); - - if (this._elements) { - if (this._elements[0] === "&") { - this._elements.shift(); - } - - } else { - this._elements = []; - } - + } else { + elements = []; } + + this._elements = elements; }; Selector.prototype.isJustParentSelector = function() { return !this.mediaEmpty && diff --git a/test/css/mixins-interpolated.css b/test/css/mixins-interpolated.css index 637b5b682..0d511fc67 100644 --- a/test/css/mixins-interpolated.css +++ b/test/css/mixins-interpolated.css @@ -1,3 +1,6 @@ +.123 { + a: 0; +} .foo { a: 1; } @@ -11,6 +14,7 @@ a: 4; } mi-test-a { + a: 0; a: 1; a: 2; a: 3; diff --git a/test/less/mixins-interpolated.less b/test/less/mixins-interpolated.less index 2e75e9805..b79fa89a6 100644 --- a/test/less/mixins-interpolated.less +++ b/test/less/mixins-interpolated.less @@ -1,8 +1,13 @@ +@a0: 123; @a1: foo; @a2: ~".foo"; @a4: ~"#foo"; +.@{a0} { + a: 0; +} + .@{a1} { a: 1; } @@ -20,6 +25,7 @@ } mi-test-a { + .123; .foo; #foo; }