How to use the @babel/traverse.traverse function in @babel/traverse

To help you get started, we’ve selected a few @babel/traverse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jdonaghue / es-search / src / matcher.js View on Github external
}

    case 'anycondition': {
      if (sourceNode) {
        let match = false;
        const matchers = {};

        queryNode.condition.estree.forEach(function (estree) {
          matchers[estree] = function (node) {
            if (matcher(node, queryNode.condition)) {
              match = true;
            }
          }
          
        });
        traverse(sourceNode, {
          enter(path) {
            Object.keys(matchers).forEach(type => (
              matchers[type](type.node)
            ));
          }
        })

        if (match) {
          return [sourceNode];
        }
      }
      break;
    }

    case 'ifstatement':
    case 'whileloop': {

@babel/traverse

The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes

MIT
Latest version published 20 days ago

Package Health Score

95 / 100
Full package analysis

Similar packages