jscodeshift-debug
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

jscodeshift-debug

Debug utilities for jscodeshift

Usage:

Install

yarn add --dev jscodeshift-debug

And use

import debug from 'jscodeshift-debug

debug(node) // or debug(nodepath)

Example

// someFileToTransform.js
import sinon from 'sinon-sandbox'

sinon.stub(I18n, 'extend');
import core, { API, FileInfo } from 'jscodeshift'

// basic jscodeshift transformer
export default function transformer(fileInfo: FileInfo, api: API, options) {
  const j = api.jscodeshift
  const ast = j(fileInfo.source)
  ast
    .find(j.CallExpression, {
      callee: {
        type: 'MemberExpression',
        property: {
          type: 'Identifier',
          name: 'stub',
        },
        object: {
          type: 'Identifier',
          name: 'sinon',
        },
      },
    })
    .forEach((nodepath) => {
      // usage:
      debug(np)
    })
}

Will log:

Node tree is:
{
  "type": "CallExpression",
  "callee": {
      "type": "MemberExpression",
      "object": {
          "type": "Identifier",
          "name": "sinon"
      },
      "property": {
          "type": "Identifier",
          "name": "stub"
      }
  },
  "arguments": [
      {
          "type": "Identifier",
          "name": "I18n"
      },
      {
          "type": "Literal",
          "value": "extend"
      }
  ]
} 
    
Node to source:
    
sinon.stub(I18n, 'extend');

Package Sidebar

Install

npm i jscodeshift-debug

Weekly Downloads

1

Version

1.1.1

License

MIT

Unpacked Size

24 kB

Total Files

8

Last publish

Collaborators

  • catc