Sha256: d92080e186ad6bd2fcd8fe52a5000e07fc62d78f7959bd5b8e16b8c5f96f1233
Contents?: true
Size: 1.67 KB
Versions: 5
Compression:
Stored size: 1.67 KB
Contents
var Node = require("./node"), Paren = require("./paren"), Comment = require("./comment"); var Expression = function (value) { this.value = value; if (!value) { throw new Error("Expression requires an array parameter"); } }; Expression.prototype = new Node(); Expression.prototype.type = "Expression"; Expression.prototype.accept = function (visitor) { this.value = visitor.visitArray(this.value); }; Expression.prototype.eval = function (context) { var returnValue, inParenthesis = this.parens && !this.parensInOp, doubleParen = false; if (inParenthesis) { context.inParenthesis(); } if (this.value.length > 1) { returnValue = new Expression(this.value.map(function (e) { return e.eval(context); })); } else if (this.value.length === 1) { if (this.value[0].parens && !this.value[0].parensInOp) { doubleParen = true; } returnValue = this.value[0].eval(context); } else { returnValue = this; } if (inParenthesis) { context.outOfParenthesis(); } if (this.parens && this.parensInOp && !(context.isMathOn()) && !doubleParen) { returnValue = new Paren(returnValue); } return returnValue; }; Expression.prototype.genCSS = function (context, output) { for (var i = 0; i < this.value.length; i++) { this.value[i].genCSS(context, output); if (i + 1 < this.value.length) { output.add(" "); } } }; Expression.prototype.throwAwayComments = function () { this.value = this.value.filter(function(v) { return !(v instanceof Comment); }); }; module.exports = Expression;
Version data entries
5 entries across 5 versions & 2 rubygems