unaryop.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*!
  2. * Stylus - UnaryOp
  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 `UnaryOp` with `op`, and `expr`.
  12. *
  13. * @param {String} op
  14. * @param {Node} expr
  15. * @api public
  16. */
  17. var UnaryOp = module.exports = function UnaryOp(op, expr){
  18. Node.call(this);
  19. this.op = op;
  20. this.expr = expr;
  21. };
  22. /**
  23. * Inherit from `Node.prototype`.
  24. */
  25. UnaryOp.prototype.__proto__ = Node.prototype;
  26. /**
  27. * Return a clone of this node.
  28. *
  29. * @return {Node}
  30. * @api public
  31. */
  32. UnaryOp.prototype.clone = function(parent){
  33. var clone = new UnaryOp(this.op);
  34. clone.expr = this.expr.clone(parent, clone);
  35. clone.lineno = this.lineno;
  36. clone.column = this.column;
  37. clone.filename = this.filename;
  38. return clone;
  39. };
  40. /**
  41. * Return a JSON representation of this node.
  42. *
  43. * @return {Object}
  44. * @api public
  45. */
  46. UnaryOp.prototype.toJSON = function(){
  47. return {
  48. __type: 'UnaryOp',
  49. op: this.op,
  50. expr: this.expr,
  51. lineno: this.lineno,
  52. column: this.column,
  53. filename: this.filename
  54. };
  55. };