ternary.js 1.3 KB

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