sarsamurmu / estree-toolkit

Tools for working with ESTree AST
https://estree-toolkit.netlify.app/
MIT License
54 stars 1 forks source link

Enable a way to skip traversal of all children #9

Closed trueadm closed 3 months ago

trueadm commented 1 year ago

Today path.skip() only applies to the current node, it would be great to skip the traversal of all children of that given path too.

Rich-Harris commented 1 year ago

Or better still, abort all subsequent traversal:

traverse(program, {
  Identifier(path) {
    if (path.node.name === 'Waldo') {
      console.log('found him');
      path.abort();
    }
  }
});
sarsamurmu commented 1 year ago

We have something similar to abort - https://estree-toolkit.netlify.app/traversal/#stopping-traversal. But it totally stops the traversal, so I don't think it's what you want.

sarsamurmu commented 1 year ago

New version has it - skipChildren

Rich-Harris commented 1 year ago

Fantastic, thanks so much! this.stop() is what I was looking for, but skipChildren is also super helpful