walk.js 425 B

12345678910111213141516171819202122
  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 (
  9. result !== false &&
  10. node.type === "function" &&
  11. Array.isArray(node.nodes)
  12. ) {
  13. walk(node.nodes, cb, bubble);
  14. }
  15. if (bubble) {
  16. cb(node, i, nodes);
  17. }
  18. }
  19. };