params.js 1.4 KB

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