diff --git a/lib/less/tree/anonymous.js b/lib/less/tree/anonymous.js index 460c9ec7..44614906 100644 --- a/lib/less/tree/anonymous.js +++ b/lib/less/tree/anonymous.js @@ -7,7 +7,21 @@ tree.Anonymous.prototype = { toCSS: function () { return this.value; }, - eval: function () { return this } + eval: function () { return this }, + compare: function (x) { + if (!x.toCSS) { + return -1; + } + + var left = this.toCSS(), + right = x.toCSS(); + + if (left === right) { + return 0; + } + + return left < right ? -1 : 1; + } }; })(require('../tree')); diff --git a/lib/less/tree/color.js b/lib/less/tree/color.js index 37ce1781..6adf3179 100644 --- a/lib/less/tree/color.js +++ b/lib/less/tree/color.js @@ -94,6 +94,16 @@ tree.Color.prototype = { i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16); return i.length === 1 ? '0' + i : i; }).join(''); + }, + compare: function (x) { + if (!x.rgb) { + return -1; + } + + return (x.rgb[0] === this.rgb[0] && + x.rgb[1] === this.rgb[1] && + x.rgb[2] === this.rgb[2] && + x.alpha === this.alpha) ? 0 : -1; } }; diff --git a/lib/less/tree/quoted.js b/lib/less/tree/quoted.js index 794bf4ce..f93dc8e1 100644 --- a/lib/less/tree/quoted.js +++ b/lib/less/tree/quoted.js @@ -23,6 +23,20 @@ tree.Quoted.prototype = { return ('value' in v) ? v.value : v.toCSS(); }); return new(tree.Quoted)(this.quote + value + this.quote, value, this.escaped, this.index); + }, + compare: function (x) { + if (!x.toCSS) { + return -1; + } + + var left = this.toCSS(), + right = x.toCSS(); + + if (left === right) { + return 0; + } + + return left < right ? -1 : 1; } }; diff --git a/lib/less/tree/ruleset.js b/lib/less/tree/ruleset.js index 80203f90..f5f397ef 100644 --- a/lib/less/tree/ruleset.js +++ b/lib/less/tree/ruleset.js @@ -10,7 +10,8 @@ tree.Ruleset.prototype = { eval: function (env) { var selectors = this.selectors && this.selectors.map(function (s) { return s.eval(env) }); var ruleset = new(tree.Ruleset)(selectors, this.rules.slice(0), this.strictImports); - + var rules = []; + ruleset.root = this.root; ruleset.allowImports = this.allowImports; @@ -21,10 +22,13 @@ tree.Ruleset.prototype = { if (ruleset.root || ruleset.allowImports || !ruleset.strictImports) { for (var i = 0; i < ruleset.rules.length; i++) { if (ruleset.rules[i] instanceof tree.Import) { - Array.prototype.splice - .apply(ruleset.rules, [i, 1].concat(ruleset.rules[i].eval(env))); + rules = rules.concat(ruleset.rules[i].eval(env)); + } else { + rules.push(ruleset.rules[i]); } } + ruleset.rules = rules; + rules = []; } // Store the frames around mixin definitions, @@ -38,10 +42,12 @@ tree.Ruleset.prototype = { // Evaluate mixin calls. for (var i = 0; i < ruleset.rules.length; i++) { if (ruleset.rules[i] instanceof tree.mixin.Call) { - Array.prototype.splice - .apply(ruleset.rules, [i, 1].concat(ruleset.rules[i].eval(env))); + rules = rules.concat(ruleset.rules[i].eval(env)); + } else { + rules.push(ruleset.rules[i]); } } + ruleset.rules = rules; // Evaluate everything else for (var i = 0, rule; i < ruleset.rules.length; i++) { diff --git a/test/css/mixins-guards.css b/test/css/mixins-guards.css index 0c563e52..cd94c010 100644 --- a/test/css/mixins-guards.css +++ b/test/css/mixins-guards.css @@ -56,3 +56,13 @@ content: not false; content: not false and false, not false; } +.colorguardtest { + content: is #ff0000; + content: is not #0000ff its #ff0000; + content: is not #0000ff its #800080; +} +.stringguardtest { + content: is theme1; + content: is not theme2; + content: is theme1 no quotes; +} diff --git a/test/less-test.js b/test/less-test.js index 806fe1d0..57f7aa3d 100644 --- a/test/less-test.js +++ b/test/less-test.js @@ -29,7 +29,7 @@ fs.readdirSync('test/less').forEach(function (file) { else if (err) { sys.print(stylize("ERROR: " + (err && err.message), 'red')); } else { - sys.print(stylize("FAIL", 'yellow')); + sys.print(stylize("FAIL", 'yellow') + '\n'); require('diff').diffLines(css, less).forEach(function(item) { if(item.added || item.removed) { diff --git a/test/less/mixins-guards.less b/test/less/mixins-guards.less index 1f46e976..3e27c268 100644 --- a/test/less/mixins-guards.less +++ b/test/less/mixins-guards.less @@ -92,3 +92,22 @@ .bool () when not (false) and (false), not (false) { content: not false and false, not false } .bool1 { .bool } + +.colorguard(@col) when (@col = red) { content: is @col; } +.colorguard(@col) when not (blue = @col) { content: is not blue its @col; } +.colorguard(@col) {} +.colorguardtest { + .colorguard(red); + .colorguard(blue); + .colorguard(purple); +} + +.stringguard(@str) when (@str = "theme1") { content: is theme1; } +.stringguard(@str) when not ("theme2" = @str) { content: is not theme2; } +.stringguard(@str) when (~"theme1" = @str) { content: is theme1 no quotes; } +.stringguard(@str) {} +.stringguardtest { + .stringguard("theme1"); + .stringguard("theme2"); + .stringguard(theme1); +} \ No newline at end of file