mirror of
https://github.com/less/less.js.git
synced 2026-01-22 13:48:03 -05:00
75 lines
2.0 KiB
JavaScript
75 lines
2.0 KiB
JavaScript
var Node = function() {
|
|
};
|
|
Node.prototype.toCSS = function (context) {
|
|
var strs = [];
|
|
this.genCSS(context, {
|
|
add: function(chunk, fileInfo, index) {
|
|
strs.push(chunk);
|
|
},
|
|
isEmpty: function () {
|
|
return strs.length === 0;
|
|
}
|
|
});
|
|
return strs.join('');
|
|
};
|
|
Node.prototype.genCSS = function (context, output) {
|
|
output.add(this.value);
|
|
};
|
|
Node.prototype.accept = function (visitor) {
|
|
this.value = visitor.visit(this.value);
|
|
};
|
|
Node.prototype.eval = function () { return this; };
|
|
Node.prototype._operate = function (context, op, a, b) {
|
|
switch (op) {
|
|
case '+': return a + b;
|
|
case '-': return a - b;
|
|
case '*': return a * b;
|
|
case '/': return a / b;
|
|
}
|
|
};
|
|
Node.prototype.fround = function(context, value) {
|
|
var precision = context && context.numPrecision;
|
|
//add "epsilon" to ensure numbers like 1.000000005 (represented as 1.000000004999....) are properly rounded...
|
|
return (precision == null) ? value : Number((value + 2e-16).toFixed(precision));
|
|
};
|
|
Node.compare = function (a, b) {
|
|
/* returns:
|
|
-1: a < b
|
|
0: a = b
|
|
1: a > b
|
|
and *any* other value for a != b (e.g. undefined, NaN, -2 etc.) */
|
|
|
|
if ((a.compare) &&
|
|
// for "symmetric results" force toCSS-based comparison
|
|
// of Quoted or Anonymous if either value is one of those
|
|
!(b.type === "Quoted" || b.type === "Anonymous")) {
|
|
return a.compare(b);
|
|
} else if (b.compare) {
|
|
return -b.compare(a);
|
|
} else if (a.type !== b.type) {
|
|
return undefined;
|
|
}
|
|
|
|
a = a.value;
|
|
b = b.value;
|
|
if (!Array.isArray(a)) {
|
|
return a === b ? 0 : undefined;
|
|
}
|
|
if (a.length !== b.length) {
|
|
return undefined;
|
|
}
|
|
for (var i = 0; i < a.length; i++) {
|
|
if (Node.compare(a[i], b[i]) !== 0) {
|
|
return undefined;
|
|
}
|
|
}
|
|
return 0;
|
|
};
|
|
|
|
Node.numericCompare = function (a, b) {
|
|
return a < b ? -1
|
|
: a === b ? 0
|
|
: a > b ? 1 : undefined;
|
|
};
|
|
module.exports = Node;
|