1.1.1 • Published 2 years ago

jscodeshift-debug v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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');
1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago