Files
less.js/lib/less/tree/condition.js
Luke Page cf0ac69767 Merge branch 'reworked-guard-comparison' of github.com:seven-phases-max/less.js into 2_0_0
Conflicts:
	lib/less/tree.js
	lib/less/tree/anonymous.js
	lib/less/tree/color.js
	lib/less/tree/condition.js
	lib/less/tree/dimension.js
	lib/less/tree/keyword.js
	lib/less/tree/quoted.js
2014-09-06 01:52:47 +01:00

34 lines
1.1 KiB
JavaScript

var Node = require("./node.js");
var Condition = function (op, l, r, i, negate) {
this.op = op.trim();
this.lvalue = l;
this.rvalue = r;
this.index = i;
this.negate = negate;
};
Condition.prototype = new Node();
Condition.prototype.type = "Condition";
Condition.prototype.accept = function (visitor) {
this.lvalue = visitor.visit(this.lvalue);
this.rvalue = visitor.visit(this.rvalue);
};
Condition.prototype.eval = function (env) {
var result = (function (op, a, b) {
switch (op) {
case 'and': return a && b;
case 'or': return a || b;
default:
switch (Node.compare(a, b)) {
case -1: return op === '<' || op === '=<' || op === '<=';
case 0: return op === '=' || op === '>=' || op === '=<' || op === '<=';
case 1: return op === '>' || op === '>=';
default: return false;
}
}
}) (this.op, this.lvalue.eval(env), this.rvalue.eval(env));
return this.negate ? !result : result;
};
module.exports = Condition;