(WIP) feat: Add :scope and :root selectors#37
(WIP) feat: Add :scope and :root selectors#37run1t wants to merge 14 commits intophenomnomnominal:masterfrom
:scope and :root selectors#37Conversation
| 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.
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.
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 ?
| return results; | ||
| } | ||
|
|
||
| if (selector.left) { |
There was a problem hiding this comment.
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.
| }, | ||
| "dependencies": { | ||
| "esquery": "^1.0.1" | ||
| "esquery-scope": "^1.1.0" |
There was a problem hiding this comment.
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
:rootselector work. But after adding tests cases discussed with @petebacondarwin the implementation of:rootfromESqueryis not sufficient to cover the use cases defined below.However I added the tests to cover the use cases.
Base example
Uses cases
:root
rootof the example::root > FunctionDeclarationshould return thefunction aBLOCKof thefunction a::root > FunctionDeclarationshould return thefunction a:root FunctionDeclarationshould return thefunction aanfunction b:scope
rootof the example::scope > FunctionDeclarationshould return thefunction aBLOCKof thefunction a::scope > FunctionDeclarationshould return thefunction b:scope FunctionDeclarationshould return thefunction b