mysticatea / regexpp

The regular expression parser for ECMAScript.
MIT License
153 stars 15 forks source link

Expose parents in regexp vistor #16

Open connor4312 opened 3 years ago

connor4312 commented 3 years ago

Right now in the visitor it's not possible to see the chain of parent nodes, unless you add a handler for every single node type and maintain your own array. It'd be useful to pass the parents in as a second parameter.

RunDevelopment commented 3 years ago

@connor4312 Couldn't you use the parent property each node has to walk up the tree? Kinda like this:

function getParents(node: AST.Node): AST.Node[] {
  const path: AST.Node[] = [];
  let n = node.parent;
  for (; n; n = n.parent) {
    path.push(n);
  }
  return path.reverse();
}
MichaelDeBoey commented 1 year ago

Hi @connor4312!

Since this repo is unmaintained, you might want to re-open this issue in the @eslint-community fork https://github.com/eslint-community/regexpp

For more info about why we created this organization, you can read https://eslint.org/blog/2023/03/announcing-eslint-community-org