value.js 925 B

12345678910111213141516171819202122232425262728293031323334
  1. var Node = require("./node");
  2. var Value = function (value) {
  3. this.value = value;
  4. if (!value) {
  5. throw new Error("Value requires an array argument");
  6. }
  7. };
  8. Value.prototype = new Node();
  9. Value.prototype.type = "Value";
  10. Value.prototype.accept = function (visitor) {
  11. if (this.value) {
  12. this.value = visitor.visitArray(this.value);
  13. }
  14. };
  15. Value.prototype.eval = function (context) {
  16. if (this.value.length === 1) {
  17. return this.value[0].eval(context);
  18. } else {
  19. return new Value(this.value.map(function (v) {
  20. return v.eval(context);
  21. }));
  22. }
  23. };
  24. Value.prototype.genCSS = function (context, output) {
  25. var i;
  26. for (i = 0; i < this.value.length; i++) {
  27. this.value[i].genCSS(context, output);
  28. if (i + 1 < this.value.length) {
  29. output.add((context && context.compress) ? ',' : ', ');
  30. }
  31. }
  32. };
  33. module.exports = Value;