UNPKG

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