walk.js 471 B

123456789101112131415161718
  1. module.exports = function walk(nodes, cb, bubble) {
  2. var i, max, node, result;
  3. for (i = 0, max = nodes.length; i < max; i += 1) {
  4. node = nodes[i];
  5. if (!bubble) {
  6. result = cb(node, i, nodes);
  7. }
  8. if (result !== false && node.type === 'function' && Array.isArray(node.nodes)) {
  9. walk(node.nodes, cb, bubble);
  10. }
  11. if (bubble) {
  12. cb(node, i, nodes);
  13. }
  14. }
  15. };