Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add support for custom visitor keys. #111

Closed
ota-meshi opened this issue Jun 19, 2020 · 2 comments · Fixed by #112
Closed

Feature Request: Add support for custom visitor keys. #111

ota-meshi opened this issue Jun 19, 2020 · 2 comments · Fixed by #112

Comments

@ota-meshi
Copy link
Contributor

I want esquery to add support for custom visitor keys.
Currently, some queries crash when using a node type unknown to estraverse.
e.g. ":nth-child(1)" (See also to #110, #67)

I think that the node type decided by estree will be fixed by version upgrade, but using JSX and TypeScript nodes will continue to crash.

If esquery can support custom visitor keys, passing custom visitor keys for JSX and TypeScript allows people to use esquery in JSX and TypeScript nodes without crashing.

@octogonz
Copy link

octogonz commented Oct 3, 2020

Another option would be to simply fail to match unrecognized nodes.

Where esquery does this:

esquery/esquery.js

Lines 309 to 312 in e27e73d

const keys = estraverse.VisitorKeys[parent.type];
for (const key of keys) {
const listProp = parent[key];
if (Array.isArray(listProp)) {

...it could avoid crashing by simply doing this:

  const keys = estraverse.VisitorKeys[parent.type]; 

  if (keys === undefined) {
    return false;  // <--------------------
  }

  for (const key of keys) { 
    const listProp = parent[key]; 
    if (Array.isArray(listProp)) { 

@octogonz
Copy link

octogonz commented Oct 3, 2020

Also, fixing #114 would probably cause the query engine to skip a lot of cases where this is encountered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants