tsquery
tsquery copied to clipboard
(WIP) feat: Add `:scope` and `:root` selectors
trafficstars
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
rootof the example:- ✅ Executing this query
:root > FunctionDeclarationshould return thefunction a
- ✅ Executing this query
- Assuming we are in the
BLOCKof thefunction a:- ✅ Executing this query
:root > FunctionDeclarationshould return thefunction a - ✅ Executing this query
:root FunctionDeclarationshould return thefunction aanfunction b
- ✅ Executing this query
:scope
- Assuming we are in the
rootof the example:- ✅ Executing this query
:scope > FunctionDeclarationshould return thefunction a
- ✅ Executing this query
- Assuming we are in the
BLOCKof thefunction a:- ✅ Executing this query
:scope > FunctionDeclarationshould return thefunction b - ✅ Executing this query
:scope FunctionDeclarationshould 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.