Comments (7)
Given the following code:
require('N/algo')
This selector selects the text N/algo
in the first position in the argument list to require
:
CallExpression[callee.name='require']>.arguments:nth-child(1)[value='N/algo']
from esquery.
But what happen if I have several arguments, and I don't know the order of the one I'm searching for. For example, with this code:
requite('N/one', 'N/two', 'N/three')
What happen if I want to select 'N/two', but I don't know its position within the list of arguments?
from esquery.
Just drop the :nth-child(1)
, making sure there is no space between .arguments
and [value=…]
. It seems slightly counterintuitive at first, but the .arguments
is actually like a CSS class on each of the direct children of the CallExpression.
from esquery.
Thank you for your response, that works. But what I actually need is to select an element within an array that is an argument of a CallExpression. I supposed that should be something like this: CallExpression[callee.name='require']>.arguments.0.elements[value='N/one']
But it's not working for the following code:
require(["N/one", "N/two"]);
Any ideas?
from esquery.
How specific does it have to be? This will match your string nested anywhere within the arguments
CallExpression[callee.name='require'] Literal[value='N/one']
from esquery.
Otherwise, this will match only an array given as the first argument, containing your string literal in any position:
CallExpression[callee.name='require']
> ArrayExpression.arguments:first-child
> Literal.elements[value='N/one']
from esquery.
That work's!! Thank you so much.
from esquery.
Related Issues (20)
- Request to update the dependence `estraverse` to latest
- Do not bundle estraverse dependency? HOT 1
- Demo: support for different parsers? HOT 4
- Support back-references with wildcards
- Crash on optional chaining HOT 3
- Feature Request: Add support for custom visitor keys. HOT 2
- Change match order to avoid inefficient comparisons HOT 1
- Question: How can I match a specific child of a parent? HOT 1
- Proposal: Support check types HOT 3
- `:has(selector)` matches nodes matched by `selector` HOT 1
- TypeError: esquery.parse is not a function
- Attribute value doesn't support empty array ([]) HOT 1
- Feature Request: Add `:is` as alias for `:matches`
- Building esquery using sample code
- Python port
- :has(> child) is not supported HOT 4
- eslint crash when upgrading to 1.4.1 HOT 13
- how to use esquery with ts-morph? HOT 2
- Help with array null child selector HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esquery.