1. jscodeshift-helper
a utility to help you explore jscodeshift
jscodeshift-helper
Package: jscodeshift-helper
Created by: reergymerej
Last modified: Sun, 19 Jun 2022 05:52:53 GMT
Version: 1.1.0
License: ISC
Downloads: 8,772
Repository: https://github.com/reergymerej/jscodeshift-helper

Install

npm install jscodeshift-helper
yarn add jscodeshift-helper

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

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code