tsquery
tsquery copied to clipboard
(WIP) feat: Add `:scope` and `:root` selectors
As said in #23 I thought the :root
selector work. But after adding tests cases discussed with @petebacondarwin the implementation of :root
from ESquery
is not sufficient to cover the use cases defined below.
However I added the tests to cover the use cases.
Base example
function a() {
function b() {
return 'bar';
}
return 'foo';
};
Uses cases
:root
- Assuming we are in the
root
of the example:- ✅ Executing this query
:root > FunctionDeclaration
should return thefunction a
- ✅ Executing this query
- Assuming we are in the
BLOCK
of thefunction a
:- ✅ Executing this query
:root > FunctionDeclaration
should return thefunction a
- ✅ Executing this query
:root FunctionDeclaration
should return thefunction a
anfunction b
- ✅ Executing this query
:scope
- Assuming we are in the
root
of the example:- ✅ Executing this query
:scope > FunctionDeclaration
should return thefunction a
- ✅ Executing this query
- Assuming we are in the
BLOCK
of thefunction a
:- ✅ Executing this query
:scope > FunctionDeclaration
should return thefunction b
- ✅ Executing this query
:scope FunctionDeclaration
should return thefunction b
- ✅ Executing this query
Is this going to get merged in?
Not until we get the upstream fix merged I'm afraid. I thought I did a review of the PR in the esquery repo, but it's vanished. I'll do it again and see if we can get @run1t's changes merged there.