each.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*!
  2. * Stylus - Each
  3. * Copyright (c) Automattic <developer.wordpress.com>
  4. * MIT Licensed
  5. */
  6. /**
  7. * Module dependencies.
  8. */
  9. var Node = require('./node')
  10. , nodes = require('./');
  11. /**
  12. * Initialize a new `Each` node with the given `val` name,
  13. * `key` name, `expr`, and `block`.
  14. *
  15. * @param {String} val
  16. * @param {String} key
  17. * @param {Expression} expr
  18. * @param {Block} block
  19. * @api public
  20. */
  21. var Each = module.exports = function Each(val, key, expr, block){
  22. Node.call(this);
  23. this.val = val;
  24. this.key = key;
  25. this.expr = expr;
  26. this.block = block;
  27. };
  28. /**
  29. * Inherit from `Node.prototype`.
  30. */
  31. Each.prototype.__proto__ = Node.prototype;
  32. /**
  33. * Return a clone of this node.
  34. *
  35. * @return {Node}
  36. * @api public
  37. */
  38. Each.prototype.clone = function(parent){
  39. var clone = new Each(this.val, this.key);
  40. clone.expr = this.expr.clone(parent, clone);
  41. clone.block = this.block.clone(parent, clone);
  42. clone.lineno = this.lineno;
  43. clone.column = this.column;
  44. clone.filename = this.filename;
  45. return clone;
  46. };
  47. /**
  48. * Return a JSON representation of this node.
  49. *
  50. * @return {Object}
  51. * @api public
  52. */
  53. Each.prototype.toJSON = function(){
  54. return {
  55. __type: 'Each',
  56. val: this.val,
  57. key: this.key,
  58. expr: this.expr,
  59. block: this.block,
  60. lineno: this.lineno,
  61. column: this.column,
  62. filename: this.filename
  63. };
  64. };