index.js 530 B

12345678910111213141516171819202122232425262728293031
  1. /*!
  2. * Stylus - Visitor
  3. * Copyright (c) Automattic <developer.wordpress.com>
  4. * MIT Licensed
  5. */
  6. /**
  7. * Initialize a new `Visitor` with the given `root` Node.
  8. *
  9. * @param {Node} root
  10. * @api private
  11. */
  12. var Visitor = module.exports = function Visitor(root) {
  13. this.root = root;
  14. };
  15. /**
  16. * Visit the given `node`.
  17. *
  18. * @param {Node|Array} node
  19. * @api public
  20. */
  21. Visitor.prototype.visit = function(node, fn){
  22. var method = 'visit' + node.constructor.name;
  23. if (this[method]) return this[method](node);
  24. return node;
  25. };