-
Notifications
You must be signed in to change notification settings - Fork 30
(WIP) feat: Add :scope and :root selectors
#37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
| 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 ?
| 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.
| }, | ||
| "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
: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