GithubHelp home page GithubHelp logo

Comments (5)

fkling avatar fkling commented on April 27, 2024 2

Recast (ast-types actually) provides two APIs: One lets you access the underlying "raw" AST node, with .value or .node, as you already know. The other gives you a NodePath instead of the raw AST node value.

Examples:

var args = path.value.arguments; // array of AST nodes
var args = path.get('arguments'); // NodePath representing the array of AST nodes

.get takes multiple arguments. To get the NodePath to the first AST node in arguments, you can do:

var pathToFirstArg = path.get('arguments', 0); // or args.get(0) from above

See also https://github.com/benjamn/ast-types#nodepath .

Wrapping the element with j() gives me ...

j will always return a collection of NodePaths.

from jscodeshift.

TheSavior avatar TheSavior commented on April 27, 2024

Perfect. Thanks, that helped me get there.

Do you have any thoughts as to where I should put this codemod transform? I'm either going to start a repo myself or open a PR to a pre-existing collection of transforms. Do you have any opinions on where it should go?

I imagine there is a lot of value for people who start without Babel/JSX and want to convert their codebase later to use JSX.

from jscodeshift.

cpojer avatar cpojer commented on April 27, 2024

Feel free to create your own repo or send a PR to https://github.com/cpojer/js-codemod which I have used as a collection of useful codemods that I ran at FB.

from jscodeshift.

fkling avatar fkling commented on April 27, 2024

@cpojer: What about https://github.com/reactjs/react-codemod ? Is that more for API changes between versions?

from jscodeshift.

cpojer avatar cpojer commented on April 27, 2024

Oh yeah, react-codemod is fine for React specific codemods.

from jscodeshift.

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.