feat: add support for `:scope` selector
See original GitHub issueSee https://developer.mozilla.org/en-US/docs/Web/CSS/:scope
This selector would allow queries to limit the matching to only the direct children of the AST on which the query is run.
For example, in the following code:
const x = function() {
function y() {
return 'bar';
}
return 'foo';
};
How do you query for just the outer function’s return statement? Currently the query ReturnStatement
will return both return statements even if it is run on the Block
node that is the body of the outer function.
With the :scope
selector you would be able to use :scope > ReturnStatement
and then run that on the body of the outer function to only return the outer ReturnStatement
.
ESQuery has a PR for adding this already https://github.com/estools/esquery/pull/61
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:25 (7 by maintainers)
Top Results From Across the Web
supports - CSS: Cascading Style Sheets - MDN Web Docs
This function evaluates if a browser supports the specified selector syntax. The following example returns true and applies the CSS style if ...
Read more >Scoped CSS - Vue Loader
Dynamically Generated Content. DOM content created with v-html are not affected by scoped styles, but you can still style them using deep selectors....
Read more >Confluent Platform コンポーネントの更新履歴 | Confluent ...
PR-10152 - KAFKA-12339: Add retry to admin client's listOffsets ... PR-5644 - fix: support GROUP BY with no source columns used; PR-5638 -...
Read more >Choosing the Right Scope Mount for Your Rifle - Leupold
Our 45-degree rail mounts and ring top mounts are growing in popularity, with the latter featuring a mounting plate that can move to...
Read more >February 2022 (version 1.65) - Visual Studio Code
navigationScope makes it possible to scope editor history navigation to just the active editor group or even editor. Supported values are:.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ah yep, too right. Once their PR gets merged and released I can port over the matcher and the tests too.
If I’m understanding this correctly, I think
:root
would be the same asSourceFile?
. Example,SourceFile>FunctionDeclaration
will select root function declarations whileFunctionDeclaration
will select all.Or an I missing something ?About the question, you select the outer ReturnStatement like this:
FunctionExpression >Block > * > ReturnStatement
. Or more specific:SourceFile>FunctionExpression >Block > * > ReturnStatement
.The ‘*’ would be a SyntaxList but seems is treated specially and you cannot mention it in the query (i.e this works:
FunctionExpression >Block > SyntaxList
, this won’t work:FunctionExpression >Block > SyntaxList *
)About
:scope
, IMO, in the context of JavaScript it could be confused with a symbol scope. My two cents