call.js 1.5 KB

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