estree-toolkit icon indicating copy to clipboard operation
estree-toolkit copied to clipboard

Enable a way to skip traversal of all children

Open trueadm opened this issue 1 year ago • 4 comments

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.

trueadm avatar Aug 10 '23 19:08 trueadm

Or better still, abort all subsequent traversal:

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

Rich-Harris avatar Aug 10 '23 19:08 Rich-Harris

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 avatar Aug 11 '23 05:08 sarsamurmu

New version has it - skipChildren

sarsamurmu avatar Aug 11 '23 08:08 sarsamurmu

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

Rich-Harris avatar Aug 11 '23 13:08 Rich-Harris