arguments.js 1.7 KB

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