token.js 913 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*!
  2. * Stylus - Token
  3. * Copyright (c) Automattic <developer.wordpress.com>
  4. * MIT Licensed
  5. */
  6. /**
  7. * Module dependencies.
  8. */
  9. var inspect = require('util').inspect;
  10. /**
  11. * Initialize a new `Token` with the given `type` and `val`.
  12. *
  13. * @param {String} type
  14. * @param {Mixed} val
  15. * @api private
  16. */
  17. var Token = exports = module.exports = function Token(type, val) {
  18. this.type = type;
  19. this.val = val;
  20. };
  21. /**
  22. * Custom inspect.
  23. *
  24. * @return {String}
  25. * @api public
  26. */
  27. Token.prototype.inspect = function(){
  28. var val = ' ' + inspect(this.val);
  29. return '[Token:' + this.lineno + ':' + this.column + ' '
  30. + '\x1b[32m' + this.type + '\x1b[0m'
  31. + '\x1b[33m' + (this.val ? val : '') + '\x1b[0m'
  32. + ']';
  33. };
  34. /**
  35. * Return type or val.
  36. *
  37. * @return {String}
  38. * @api public
  39. */
  40. Token.prototype.toString = function(){
  41. return (undefined === this.val
  42. ? this.type
  43. : this.val).toString();
  44. };