member.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*!
  2. * Stylus - Member
  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 `Member` with `left` and `right`.
  12. *
  13. * @param {Node} left
  14. * @param {Node} right
  15. * @api public
  16. */
  17. var Member = module.exports = function Member(left, right){
  18. Node.call(this);
  19. this.left = left;
  20. this.right = right;
  21. };
  22. /**
  23. * Inherit from `Node.prototype`.
  24. */
  25. Member.prototype.__proto__ = Node.prototype;
  26. /**
  27. * Return a clone of this node.
  28. *
  29. * @return {Node}
  30. * @api public
  31. */
  32. Member.prototype.clone = function(parent){
  33. var clone = new Member;
  34. clone.left = this.left.clone(parent, clone);
  35. clone.right = this.right.clone(parent, clone);
  36. if (this.val) clone.val = this.val.clone(parent, clone);
  37. clone.lineno = this.lineno;
  38. clone.column = this.column;
  39. clone.filename = this.filename;
  40. return clone;
  41. };
  42. /**
  43. * Return a JSON representation of this node.
  44. *
  45. * @return {Object}
  46. * @api public
  47. */
  48. Member.prototype.toJSON = function(){
  49. var json = {
  50. __type: 'Member',
  51. left: this.left,
  52. right: this.right,
  53. lineno: this.lineno,
  54. column: this.column,
  55. filename: this.filename
  56. };
  57. if (this.val) json.val = this.val;
  58. return json;
  59. };
  60. /**
  61. * Return a string representation of this node.
  62. *
  63. * @return {String}
  64. * @api public
  65. */
  66. Member.prototype.toString = function(){
  67. return this.left.toString()
  68. + '.' + this.right.toString();
  69. };