namespace.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*!
  2. * Stylus - Namespace
  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 `Namespace` with the given `val` and `prefix`
  12. *
  13. * @param {String|Call} val
  14. * @param {String} [prefix]
  15. * @api public
  16. */
  17. var Namespace = module.exports = function Namespace(val, prefix){
  18. Node.call(this);
  19. this.val = val;
  20. this.prefix = prefix;
  21. };
  22. /**
  23. * Inherit from `Node.prototype`.
  24. */
  25. Namespace.prototype.__proto__ = Node.prototype;
  26. /**
  27. * Return @namespace "val".
  28. *
  29. * @return {String}
  30. * @api public
  31. */
  32. Namespace.prototype.toString = function(){
  33. return '@namespace ' + (this.prefix ? this.prefix + ' ' : '') + this.val;
  34. };
  35. /**
  36. * Return a JSON representation of this node.
  37. *
  38. * @return {Object}
  39. * @api public
  40. */
  41. Namespace.prototype.toJSON = function(){
  42. return {
  43. __type: 'Namespace',
  44. val: this.val,
  45. prefix: this.prefix,
  46. lineno: this.lineno,
  47. column: this.column,
  48. filename: this.filename
  49. };
  50. };