question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat: add support for `:scope` selector

See original GitHub issue

See 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:open
  • Created 5 years ago
  • Reactions:2
  • Comments:25 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
phenomnomnominalcommented, Nov 12, 2018

Ah yep, too right. Once their PR gets merged and released I can port over the matcher and the tests too.

0reactions
cancerberoSgxcommented, Apr 10, 2019

If I’m understanding this correctly, I think:root would be the same as SourceFile?. Example, SourceFile>FunctionDeclaration will select root function declarations while FunctionDeclaration 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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found