walk.js 462 B

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