recurse.js 364 B

1234567891011121314151617181920
  1. const esrecurse = require('esrecurse');
  2. const visit = (ast, visitor) => {
  3. const newVisitor = {};
  4. for (const key of Object.keys(visitor)) {
  5. const value = visitor[key];
  6. newVisitor[key] = function (node, ...rest) {
  7. value.call(this, node, ...rest);
  8. this.visitChildren(node);
  9. };
  10. }
  11. esrecurse.visit(ast, newVisitor);
  12. };
  13. module.exports = {
  14. visit,
  15. };