-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
(WIP) feat: Add :scope
and :root
selectors
#37
base: master
Are you sure you want to change the base?
Conversation
import { TSQueryOptions, TSQuerySelectorNode } from '../tsquery-types'; | ||
|
||
export function has (node: Node, selector: TSQuerySelectorNode, _: Array<Node>, options: TSQueryOptions): boolean { | ||
export function has (node: Node, selector: TSQuerySelectorNode, ancestry: Array<Node>, {}: Node, {}: TSQueryOptions): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got the :scope
selector by moving the traverseChildren
function in here. It's probably not the best way to do it.
@@ -6,17 +6,17 @@ import { tsquery } from '../src/index'; | |||
|
|||
describe('tsquery:', () => { | |||
describe('tsquery.project:', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a problem with the tests below. I don't know why but some times when I was launching the test the file.length
was incrementing even if I didn't touch the ./tsconfig.json
. Do I need to open an issue ?
const results: Array<T> = []; | ||
if (!selector) { | ||
return results; | ||
} | ||
|
||
if (selector.left) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this to be able to go back to the root node when the :root
selector is matched.
It's seems incomplete as it will only work when the :root
selector is in the left part of the selector AST root.
@@ -25,7 +25,7 @@ | |||
"prepublishOnly": "npm run build" | |||
}, | |||
"dependencies": { | |||
"esquery": "^1.0.1" | |||
"esquery-scope": "^1.1.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunatly I had to keep the esquery-scope
in order to be able to run the ci
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. |
As said in #23 I thought the
:root
selector work. But after adding tests cases discussed with @petebacondarwin the implementation of:root
fromESquery
is not sufficient to cover the use cases defined below.However I added the tests to cover the use cases.
Base example
Uses cases
:root
root
of the example::root > FunctionDeclaration
should return thefunction a
BLOCK
of thefunction a
::root > FunctionDeclaration
should return thefunction a
:root FunctionDeclaration
should return thefunction a
anfunction b
:scope
root
of the example::scope > FunctionDeclaration
should return thefunction a
BLOCK
of thefunction a
::scope > FunctionDeclaration
should return thefunction b
:scope FunctionDeclaration
should return thefunction b