estools/esquery

Subject indicator false positives

Opened this issue · 0 comments

Queries with subject indicators match more nodes than they should, and also match the same node multiple times. E.g.:

esquery(esprima.parse('foo = bar = baz'),
  '!AssignmentExpression > AssignmentExpression > Identifier');

...returns the following:

[ AssignmentExpression {
    type: 'AssignmentExpression',
    operator: '=',
    left: Identifier { type: 'Identifier', name: 'bar' },
    right: Identifier { type: 'Identifier', name: 'baz' } },
  AssignmentExpression {
    type: 'AssignmentExpression',
    operator: '=',
    left: Identifier { type: 'Identifier', name: 'foo' },
    right: 
     AssignmentExpression {
       type: 'AssignmentExpression',
       operator: '=',
       left: [Object],
       right: [Object] } },
  AssignmentExpression {
    type: 'AssignmentExpression',
    operator: '=',
    left: Identifier { type: 'Identifier', name: 'bar' },
    right: Identifier { type: 'Identifier', name: 'baz' } },
  AssignmentExpression {
    type: 'AssignmentExpression',
    operator: '=',
    left: Identifier { type: 'Identifier', name: 'foo' },
    right: 
     AssignmentExpression {
       type: 'AssignmentExpression',
       operator: '=',
       left: [Object],
       right: [Object] } } ]

As far as I can tell, it should return only this:

[ AssignmentExpression {
    type: 'AssignmentExpression',
    operator: '=',
    left: Identifier { type: 'Identifier', name: 'foo' },
    right: 
     AssignmentExpression {
       type: 'AssignmentExpression',
       operator: '=',
       left: [Object],
       right: [Object] } } ]