Giter VIP home page Giter VIP logo

Comments (7)

c-harding avatar c-harding commented on August 12, 2024 2

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.

jggsus88 avatar jggsus88 commented on August 12, 2024

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.

c-harding avatar c-harding commented on August 12, 2024

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.

jggsus88 avatar jggsus88 commented on August 12, 2024

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.

c-harding avatar c-harding commented on August 12, 2024

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.

c-harding avatar c-harding commented on August 12, 2024

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.

jggsus88 avatar jggsus88 commented on August 12, 2024

That work's!! Thank you so much.

from esquery.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.