summaryrefslogtreecommitdiff
path: root/build-tools/lib/less/tree/operation.js
diff options
context:
space:
mode:
Diffstat (limited to 'build-tools/lib/less/tree/operation.js')
-rw-r--r--build-tools/lib/less/tree/operation.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/build-tools/lib/less/tree/operation.js b/build-tools/lib/less/tree/operation.js
new file mode 100644
index 00000000..d2e4d578
--- /dev/null
+++ b/build-tools/lib/less/tree/operation.js
@@ -0,0 +1,32 @@
+(function (tree) {
+
+tree.Operation = function (op, operands) {
+ this.op = op.trim();
+ this.operands = operands;
+};
+tree.Operation.prototype.eval = function (env) {
+ var a = this.operands[0].eval(env),
+ b = this.operands[1].eval(env),
+ temp;
+
+ if (a instanceof tree.Dimension && b instanceof tree.Color) {
+ if (this.op === '*' || this.op === '+') {
+ temp = b, b = a, a = temp;
+ } else {
+ throw { name: "OperationError",
+ message: "Can't substract or divide a color from a number" };
+ }
+ }
+ return a.operate(this.op, b);
+};
+
+tree.operate = function (op, a, b) {
+ switch (op) {
+ case '+': return a + b;
+ case '-': return a - b;
+ case '*': return a * b;
+ case '/': return a / b;
+ }
+};
+
+})(require('less/tree'));