mirror of
https://github.com/less/less.js.git
synced 2026-02-10 06:55:09 -05:00
Allow comparing colors and strings. Fix a bug whereby sometimes a mixin-call or import would disappear. This makes the import test fail consistently instead of once out of 8 times depending on async order I think.
This commit is contained in:
@@ -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'));
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
Reference in New Issue
Block a user