Code Monkey home page Code Monkey logo

jscodeshift-helper's Introduction

jscodeshift-helper v1.1

a utility to help you explore jscodeshift

It can be confusing understanding the difference between Collections, NodePaths, and Nodes, let alone which one you're looking at and what its API is. This little helper will log what you're looking at, give you an API overview, and point you to references.

Installation

npm i jscodeshift-helper

Usage

var describe = require('jscodeshift-helper').describe;

...

describe(something); // logs helpful info to the console

Example Output

This is a `NodePath` wrapping the `Node`:

{ type: 'ObjectExpression',
  properties:
   [ Node {
       type: 'Property',
       start: 14,
       end: 20,
       loc: [Object],
       method: false,
       shorthand: false,
       computed: false,
       key: [Object],
       value: [Object],
       kind: 'init',
       decorators: null },
     Node {
       type: 'Property',
       start: 24,
       end: 62,
       loc: [Object],
       method: false,
       shorthand: false,
       computed: false,
       key: [Object],
       value: [Object],
       kind: 'init',
       decorators: null } ] }

Description:
    A `NodePath` (aka `Path`) wraps the actual AST node (aka `Node`) and provides information such as scope and hierarchical relationship that is not available when looking at the node in isolation.  To access the wrapped Node, use `.node` or `.value`.

Methods:
    canBeFirstInStatement -
    firstInStatement -
    getValueProperty -
    needsParens -
    prune -
    replace -

Properties:
    parent - The wrapped AST node's parent, wrapped in another `NodePath`.
    scope - Scope information about the wrapped AST node.
    node - The wrapped AST node.
    value - Same as #node

References:
    https://github.com/facebook/jscodeshift/wiki/jscodeshift-Documentation#nodepaths
    https://github.com/benjamn/ast-types#nodepath
    https://github.com/benjamn/ast-types#scope

v1.1 Changes

  • describe generic objects
  • improve description of Node props
  • print inner Node props when describing NodePath
  • print Node props before description

jscodeshift-helper's People

Contributors

reergymerej avatar

Watchers

 avatar

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.